Saturday 1 April 2017

C PROGRAM FOR ADDITON AND SUBTRACTION

Input required from the user is two numbers.

Code for sample program

#include<stdio.h>

main()

{

int a,b,opt,res;

printf("MENU");

printf("1.ADDITION \n 2.SUBTRACTION");

scanf("%d",opt);

printf("Enter two numbers");

scanf("%d %d",&a,&b);

switch(opt)

{

case 1:{ res=a+b;

break;}

case 2:{res=a-b;

break;}

default : {printf("Wrong entry");

break;}

}

printf("Result is %d",res);

}

In the above program we can compute output for both addition and subtraction using switch statements.

No comments:

Post a Comment