# Function Calculator

code:

#include<stdio.h>

{
double sum;
sum = a+b;
return sum;
}

double subtract(double a,double b)
{
double sub;
sub = a-b;
return sub;
}

double multiply(double a,double b)
{
double mul;
mul = a*b;
return mul;
}

double divide(double a,double b)
{
double div;
div = a/b;
return div;
}

int main()
{
int n;
double a,b,total;
while(1!=EOF)
{
printf("What you want to do ???\n");
printf("Type value:");
scanf("%d",&n);
if(n==1)
{
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
}
if(n==2)
{
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total=subtract(a,b);
}
if(n==3)
{
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total=multiply(a,b);
}

if(n==4)
{
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total=divide(a,b);
}
}
return 0;
}

With Switch Case:

#include<stdio.h>

{
double sum;
sum = a+b;
return sum;
}

double subtract(double a,double b)
{
double sub;
sub = a-b;
return sub;
}

double multiply(double a,double b)
{
double mul;
mul = a*b;
return mul;
}

double divide(double a,double b)
{
double div;
div = a/b;
return div;
}

int main()
{
int n;
double a,b,total;
while(1!=EOF)
{
printf("What you want to do ???\n");
printf("Type value:");
scanf("%d",&n);
switch(n)
{
case 1:
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
break;
case 2:
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total=subtract(a,b);
break;
case 3:
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total=multiply(a,b);
break;
case 4:
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total=divide(a,b);
break;
default:
// printf("You didn't press any function.");
exit(420);
}
}
return 0;
}

Another easy code:

#include<stdio.h>

{
double sum;
sum = a+b;
return sum;
}

double subtract(double a,double b)
{
double sub;
sub = a-b;
return sub;
}

double multiply(double a,double b)
{
double mul;
mul = a*b;
return mul;
}

double divide(double a,double b)
{
double div;
div = a/b;
return div;
}

int main()
{
int n;
while(1!=EOF)
{
printf("Enter two of the values:");
scanf("%lf %lf",&a,&b);
total_sub=subtract(a,b);
total_mul=multiply(a,b);
total_div=divide(a,b);