Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

4. Describe the factors that influence self-disclosure

Answered: 1 week ago

Question

1. Explain key aspects of interpersonal relationships

Answered: 1 week ago