Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program

How to write C Program a menu driven program to read two integers and find their sum, difference & product in C Programming Language ?



Solution:
/* Write a menu driven program to read two integers & find their sum, difference & product. */

#include<stdio.h>

int main()
{

signed int a[2];
signed int sum,diff,prod;
printf("Enter the two numbers to find sum,difference,product \n");
scanf("%d%d",&a[0],&a[1]);
int option='s';

printf("Enter the character \n 1 -> to find sum \n 2 -> to find difference \n 3 -> to find the product \n ");
scanf("%d",&option);

switch(option)

case 1: {
sum=a[0]+a[1];
printf("the sum of the two numbers is %d \n",sum);
  //break;
}

case 2: {
diff=a[0]-a[1];
printf("the sum of the two numbers is %d \n",diff);
//break;
}

case 3: {
prod=a[0]*a[1];
printf("the sum of the two numbers is %d \n",prod);
//break;
}

default: printf("you have entered the wrong character");

return 0;
}


Learn More :