C Program to Implement Calculator using Functions

This C Program Implements calculator using functions,functions perform the required operations and returns result to the calling function
[cc lang=”c”]
#include
int n,a,b,res;

void addnum(int a,int b)
{
printf(“%d”,a+b);
}

void subnum(int x,int y)
{
printf(“%d”,x-y);
}

void mulnum(int a,int b)
{
int p;
p=a*b;
printf(“%d”,p);
}

void divnum(int a,int b)
{
printf(“%d”,a/b);
}

int main()
{
printf(“Enter two Numbers for the Operation n”);
scanf(“%d%d”,&a,&b);

printf(“Enter n1.Additionn2.Subtractionn3.Multiplicationn4.Divisionn”);
scanf(“%d”,&n);

switch (n)
{
case 1:
addnum(a,b);
break;

case 2:
subnum(a,b);

case 3:
mulnum(a,b);

case 4:
divnum(a,b);

}
return 0;
}

[/cc]
OUTPUT:
Enter two Numbers for the Operation
12
534
Enter
1.Addition
2.Subtraction
3.Multiplication
4.Division

1
546

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *