Create a program of mathematical that will display the sum, difference, product, quotient of two variables using the interactive input.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int ch=-1;
float number1;
float number2;
float sum;
float difference;
float product;
float div;
while(ch!=5){
printf("MENU OF OPERATIONS\n");
printf("[ 1 ] - Addition\n");
printf("[ 2 ] - Subtraction\n");
printf("[ 3 ] - Multiplication\n");
printf("[ 4 ] - Division\n");
printf("[ 5 ] - Quit\n");
printf("Enter Your Choice: ");
scanf("%d",&ch);
if(ch==1){
printf("You have chosen Addition!\n");
printf("Enter the number 1: ");
scanf("%f",&number1);
printf("Enter the number 2: ");
scanf("%f",&number2);
sum=number1+number2;
printf("Sum = %.2f\n\n",sum);
}else if(ch==2){
printf("You have chosen Subtraction!\n");
printf("Enter the number 1: ");
scanf("%f",&number1);
printf("Enter the number 2: ");
scanf("%f",&number2);
difference=number1-number2;
printf("Difference = %.2f\n\n",difference);
}else if(ch==3){
printf("You have chosen Multiplication!\n");
printf("Enter the number 1: ");
scanf("%f",&number1);
printf("Enter the number 2: ");
scanf("%f",&number2);
product=number1*number2;
printf("Product = %.2f\n\n",product);
}else if(ch==4){
printf("You have chosen Division!\n");
printf("Enter the number 1: ");
scanf("%f",&number1);
printf("Enter the number 2: ");
scanf("%f",&number2);
div=(float)number1/(float)number2;
printf("Quotient = %.2f\n\n",div);
}else if(ch==6){
}else{
printf("Wrong menu item.\n\n");
}
}
getchar();
return 0;
}
Comments
Leave a comment