Design and implement a program thatdoes the following. Design your modules (func
ID: 3614568 • Letter: D
Question
Design and implement a program thatdoes the following. Design your modules (functions) so thateach is about 3 to 15 lines of code after implementation. Make sure that you can express the purpose of each module(function) in one or two sentences.
a. Gives the user a choice of determiningwhether a supplied positive integer number is a perfect number orof determining and printing all perfect numbers in a range oflow through high, where low andhigh are positive integers such that low <=high. A positive integer is a perfect number if it isequal to the sum of all its factors, including one but excludingitself. For example, 6 is a perfect number, since 6 = 1 + 2 +3, and 1, 2, and 3 are factors of 6.
b. If the user wants to determine whether asupplied number is a perfect number, the program reads an integer,verifies that it is positive, and determines and prints whether itis a perfect number.
c. If the user wants to determine allperfect numbers in a range, the program reads values forlow and high, verifies that they are positive andthat low <= high, and then determines and prints allperfect numbers in the range.
d. Executes the program in a loop until theuser wants to stop.
Explanation / Answer
please rate - thanks #include #include int menu(); int input1(); void input2(int *,int *); int perfect(int); int main() {int num1,num2,choice=0,yes,count=0; while(choice!=3) {choice=menu(); switch(choice) {case 1:num1=input1(); yes=perfect(num1); if(yes==1) printf("%d perfect ",num1); else printf("%d not perfect ",num1); break; case 2:input2(&num1,&num2); printf("Theperfect numbers between %d and %d are: ",num1,num2); do { yes=perfect(num1); if(yes==1) {printf("%d ",num1); count++; } num1++; }while(num1*b) printf("First number must beless than second number-reenter "); }while(*a>*b); } int perfect(int a) {int i,sum=1; for(i=2;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.