Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C language a) Write a function called print_divisors that takes as parameter an unsigned long number n and that displays all its divisors less

image text in transcribed

In C language

a) 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. b) Write a function called add_divisors that tak es as parameter an unsigned long number n and that returns the sum of all of n's divisors less than n. For instance, the call add_divisors (18) should return 12 +3+6+9-21 Write the function interface comment, with proper precondition and postcondition. c) 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 m's 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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions