You are to create a menu-driven program that will perform eachof these operation
ID: 3613657 • Letter: Y
Question
You are to create a menu-driven program that will perform eachof these operations:
q. Quit
The following conditions must be met:
Euclid's Algorithm to find the Greatest Common Factor oftwo non-negative integers
if x < y, swap x and y //x is the larger of the twointegers
while y !=0
remainder = x mody
x =y
y = remainder
return x
You must name your project "project3.c".
C Language Hints
Note that while functions are required, no parameter passing isrequired. The function should prompt for the inputs it needsand display its results. You may want to write an additionalfunction to display the menu. The main() function isresponsible for displaying the menu, or calling a function thatdoes so, interpreting the choice, and calling the correct functionfor each menu section, excluding Q which exits the program.
Does it appear that the menu selections are all numeric? While there are seven numeric menu selections, 'q' or 'Q'are not,so it is best to consider all menu inputs as character instead ofnumbers. Working with a single digit number is as easy asworking with an integer, just test for '1' instead of 1, '2'instead of 2, etc.
Explanation / Answer
printf("1.Add twointegers 2.
Subtract two integer 3.Multiply two integers
4.Divide two integers 5.Calculate an integer raised to apositive integer power
C 6.ompute the GCD (Greatest Common Divisor) of twointegers
7.Compute the factorial of an integer
q. Quit :");
}
scanf("%c",&choice);
if(choice =='q' || choice=='Q')
break;
if(choice <'1' || choice >'7')
continue;
if(choice!='7'){
printf("ENter two integer:");
scanf("%d %d",&num1,&num2);
}
switch(choice)
{
case '1':
add(num1,num2);
break;
case '2':
sub(num1,num2);
break;
case '3':
mul(num1,num2);
break;
case '4':
div1(num1,num2);
break;
case '5':
power(num1,num2);
break;
case '6':
gcd(num1,num2);
break;
case '7':
printf("ENter integer:");
scanf("%d",&num1);
fact(num1);
break;
}
}
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.