Write a C program using Switch Statement

#include<stdio.h>
int main()
{


int x,a,b,Add,s,m;
float d;
printf("Enter Any two Numbers");
scanf("%d%d",&a,&b);
printf(" -------------------->\n Press 1 for addtion \n Press 2 for Substraction \n Press 3 for Multiplication \n Press 4 for Division \n Press 5 to Exit");
scanf("%d",&x);
switch(x)
{
case 1:
Add=a+b;
printf("Their sum is %d \n",Add);
break;
case 2:
s=a-b;
printf("Their difference is %d \n",s);
break;
case 3:
m=a*b;
printf("their product is %d \n",m);
break;
case 4:
d=(float)a/b;
printf("%d/%d is %f \n",a,b,d);
break;
case 5:
return 0;
break;
default:
printf("Enter Valid Number!!!!!!!!!!\n");
}
return 0;
}

Post a Comment

1 Comments

  1. Very informative blog!

    Please take some time to visit my blog @
    loop in C notes

    Thanks!

    ReplyDelete