Accept two numbers and perform the following operations till the user selects Exit.

C File =>


/* Accept two numbers and perform the following operations till the user
selects Exit. 
i. Maximum 
ii. Display all numbers between the two 
iii. Sum and average 
iv. EXIT */


#include<stdio.h>
#include<stdlib.h>
int main() 
{
       int n1,n2,i,ch,sum;
      float avg;
 
      printf("\n Enter number1 : ");
      scanf("%d",&n1);
      printf("\n Enter number2 : ");
      scanf("%d",&n2);
 
      printf("\n Menu : \n1. Maximum");
      printf("\n 2. Display all numbers between %d and %d",n1,n2);
      printf("\n 3. Sum and Average of two");
      printf("\n 4. Exit\n Enter your choice (1-4) : ");
      scanf("%d",&ch);
 
      switch(ch)
     {
        case 1: if(n1>n2)
                          printf("\n Maximum = %d",n1);
                      else
                          printf("\n Maximum = %d",n2);
       break;
       case 2: for(i=n1;i<=n2;i++)
                         printf("%d\t",i);
       break;
       case 3: sum=n1+n2;
                     avg=(n1+n2)/2;
                    printf("\n Sum = %d and Average = %f",sum,avg);
      break;
      case 4: exit(0);
      break;
      default: printf("\n invalid input..");
    }
 
    return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.