Testing.

Sunday, 1 January 2017

C programming language : Write a Menu-driven program using Switch-case in C to perform mathematics operations Adition,Subtraction,Multiplication and Division.


    Write a menu driven program to perform following operations in C:
       i) Addition
      ii) Subtraction
     iii) Multiplication and
     iv) Division.

#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int optn,a,b;
float c;
printf("\n1.Add: ");
printf("\n2.Subtract: ");
printf("\n3.Multiply: ");
printf("\n4.Divide: ");
printf("\n5.Exit: ");
printf("\nWhat u want to do?: ");
scanf("%d",&optn);
switch(optn)
do
{
case 1: printf("\nEnter Numbers to Add: ");
scanf("%d %d",&a,&b);
c=a+b;
printf("Addition's Result Is= %f",c);
break;

case 2: printf("\nEnter Numbers to Subtract: ");
   scanf("%d %d",&a,&b);
c=a-b;
printf("Subtraction's Result Is= %f",c);
   break;

case 3: printf("\nEnter Numbers to Multiply: ");
   scanf("%d %d",&a,&b);
c=a*b;
printf("Multiplication's Result Is= %f",c);
break;

case 4: printf("\nEnter Numbers to Divide: ");
   scanf("%d %d",&a,&b);
c=a/b;
printf("Dividion's Result Is= %f",c);
break;

case 5: exit(0);
default :printf("\n Invalid option...");

}while(optn!=0);
getch();
}


No comments:

Post a Comment