Question: Use c language and save in a .c file Write a function called print_divisors that takes as parameter an unsigned long number n and that

Use c language and save in a .c file

Write a function called print_divisors that takes as parameter an unsigned long number n and that displays all its divisors less than n. 1 is considered a divisor. A positive integer number b is a divisor of a positive integer number a if a % b == 0. For instance, the divisors of 12 are 1, 2, 3, 4, 6, and 12. The function should only print divisors less than n. For example, if one calls print_divisors(18) the function determines the divisors are 1, 2, 3, 6, 9 and prints them in this order.

Hint: an easy way to find all divisors of n is to write a loop and try as divisors all numbers between 2 and n / 2.

Write the function interface comment, with proper precondition and postcondition.

Part 2

Write a function called add_divisors that takes as parameter an unsigned long number nand that returns the sum of all of ns divisors less than n.

For instance, the call add_divisors(18) should return 1 + 2 + 3 + 6 + 9 = 21.

Write the function interface comment, with proper precondition and postcondition.

Part 3

Write a main function that repeatedly reads a positive number m from the user and then finds (and prints to the terminal) all numbers between 2 and m for which the sum of ms divisors (including 1, but excluding m) is equal to m itself. The program ends when the user enters 0.

Test your program thoroughly so that all conditional branches are checked.

Include a screenshot in the PDF file with the program output in the terminal.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!