Code:
#include <stdio.h>
int addint (int x, int y);
int subint (int x, int y);
int multint (int x, int y);
int divideint (int x, int y);
int powerint (int x, int y);
int gcdint (int x, int y);
int factorial (int x);
int main()
{
int x=0;
int y=0;
char select;
printf("This program will perform one of the following operations \n");
printf("to two numbers based on your selection from the following menu: \n \n");
printf("1. Add two integers. \n");
printf("2. Subtract two intergers. \n");
printf("3. Multiply two integers. \n");
printf("4. Divide two integers. \n");
printf("5. Calculate integer raised to a positive power. \n");
printf("6. Compute greatest common divisor of two integers. \n");
printf("7. Compute the factorial of an integer. \n \n");
printf("To quit the program at any time, please press q or Q. \n \n");
printf("Please enter two integers: \n\n");
scanf("%d", &x);
printf("\n ");
scanf("%d", &y);
printf("\n ");
printf("Please choose desired operation from above menu. \n \n");
scanf("%c", &select);
while (select != 'q' && select != 'Q')
{
switch (select)
{
case '1':
printf("The sum of %d and %d is %d.", x, y,addint(x,y));
break;
case '2':
printf("%d minus %d is %d", x, y, subint(x,y));
break;
case '3':
printf("%d multiplied by %d is %d", x, y, multint(x,y));
break;
case '4':
printf(" %d divided by %d is %d", x, y, divideint(x,y));
break;
case '5':
printf(" %d raised to %d is %d", x, y, powerint(x,y));
break;
case '6':
printf("The greatest common denominator of %d and %d is %d", x, y, gcdint(x,y));
break;
case '7':
printf(" The value of the factorial for %d is %d", x, factorial(x));
break;
default:
printf("Incorrect value entered, please reenter.\n \n ");
break;
}
printf("This program will perform one of the following operations \n");
printf("to two numbers based on your selection from the following menu: \n \n");
printf("1. Add two integers. \n");
printf("2. Subtract two intergers. \n");
printf("3. Multiply two integers. \n");
printf("4. Divide two integers. \n");
printf("5. Calculate integer raised to a positive power. \n");
printf("6. Compute greatest common divisor of two integers. \n");
printf("7. Compute the factorial of an integer. \n \n");
printf("To quit the program at any time, please press q or Q. \n \n");
printf("Please enter two integers: \n\n");
scanf("%d", &x);
printf("\n ");
scanf("%d", &y);
printf("\n ");
printf("Please choose desired operation from above menu. \n \n");
scanf("%c", &select);
}
printf("You have terminated the program.");
return 0;
}
int addint (int x, int y)
{
return x + y;
}
int subint (int x, int y)
{
return x - y;
}
int multint (int x, int y)
{
return x * y;
}
int divideint (int x, int y)
{
if (y > 0 || y<0)
return x/y;
else
printf("Error - division by O.\n");
}
int powerint (int x, int y)
{
if (y==1)
return 1;
else
if (y<0)
printf("You cannot raise a number to a negative power!\n");
else
return x * powerint(x, y-1);
}
int gcdint (int x, int y )
{ /* will add this function in */
}
int factorial (int x)
{
if (x >= 0)
return x * factorial (x-1);
else
if (x<0)
printf("Error, negative factorial value entered.");
}
Thank you,