Sunday 2 April 2017

C Program to Create a Menu Driven Calculator


Program :-

#include < stdio.h >
main () {
    int a,b;
    int c,m;
    do{
         printf("\n enter the operands");
         scanf("%d%d",&a,&b);
         printf("enter the operations :1.addition 2.Subtraction 3.Multiplication 4.Division  5.Reminder");          scanf("%d",&c);
         if(c == 1){
                printf("%d + %d=%d",a,b,a+b);
         else if(c == 2)
                printf("%d - %d=%d",a,b,a-b);
         else if(c == 3)
                printf("%d * %d=%d",a,b,a*b);
         else if(c == 4)
                printf("%d / %d=%d",a,b,a/b);
         else if(c == 5)
                printf("%d % %d=%d",a,b,a%b);
         else
                printf("invalid option");
         printf("do you want to continue ?,if yes then enter 1 else 0);
         scanf("%d",&m);
        }
        while(m == 1);
}

Output :-
enter the operands
4
5
enter the operations :1.addition 2.Subtraction 3.Multiplication 4.Division  5.Reminder
1
4 + 5 = 9
do you want to continue ?,if yes then enter 1 else 0
0





No comments:

Post a Comment

How to Invert an SVG image using CSS ?

You can invert your svg easily by using following css code svg { -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */ filter...