#include
#include
long double add(long double, long double); //addition function prototype
long double subtract(long double,long double); //subtraction function prototype
long double multiply(long double,long double); //multiplication function prototype
long double divide(long double,long double); //division function prototype
int main()
{
long double first_number, second_number, output;
char option, response=’Y';
do
{
//clrscr();
first_number=0.00, second_number=0.0, output=0.0;
printf("\nEnter the value of the first number: ");
scanf("%Lf", &first_number);
printf("\nEnter the value of the second number: ");
scanf("%Lf", &second_number);
printf("\nArithmetic Operations");
printf("\n\tAdd\n\tSubtract\n\tMultiply\n\tDivide\nEnter Option: ");
scanf("%s", &option);
fflush(stdin);
switch(option)
{
case ‘a’: case ‘A’:
output=add(first_number,second_number);
printf("%Lg + %Lg = %Lg", first_number, second_number, output);
break;
case ’s’: case ‘S’:
output=subtract(first_number,second_number);
printf("%Lg – %Lg = %Lg", first_number, second_number, output);
break;
case ‘m’: case ‘M’:
output=multiply(first_number,second_number);
printf("%Lg * %Lg = %Lg", first_number, second_number, output);
break;
case ‘d’: case ‘D’:
if (first_number==0.00 &&second_number==0.00)
printf("\nError!!! Cannot Divide by O.");
else if(second_number==0.00)
printf("\nResult of function is undefined");
else
{
output=divide(first_number,second_number);
printf("%Lg / %Lg = %Lg", first_number, second_number,output);
}
break;
default:
printf("Unknown option entered");
break;
}
printf("\nRetry?[Y/N]: ");
scanf("%s", &response);
fflush(stdin);
}while (response==’Y'||response==’y');
printf("Exiting…");
getch();
return 0;
}
long double add(long double a, long double b)
{
return a+b;
}
long double subtract(long double a, long double b)
{
return a-b;
}
long double multiply(long double a, long double b)
{
return a*b;
}
long double divide(long double a, long double b)
{
return a/b;
}
No comments:
Post a Comment