Thursday, February 27, 2014

Function Example with switch statement

#include<stdio.h>
#include<conio.h>
void add()
{
int a, b;
printf("Enter two number :");
scanf("%d%d", &a, &b);
printf("%d+%d=%d",a, b, a+b);
}
void sub()
{
int a, b;
printf("Enter two number");
scanf("%d%d",&a,&b);
printf("%d-%d=%d",a, b,a-b);
}
main()
{
int a, b ,x;
printf("1.)Addition\n2.)Substraction\n3.)Division\n4.)Multiply\n\t\tChoose a number");
scanf("%d",&x);
switch(x)
{
case 1:
add();
break;
case 2:
sub();
break;
case 3:
printf("%d",a/b);
break;
case 4:
printf("%d",a*b);
break;
default:
printf("Invalid Key");
}
getch();
}

No comments:

Post a Comment