Functions and Recursions – Arithmetic – Problem #5

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

Problem Statement

We call a positive integer n a beautiful number if n is equal to the sum of its proper divisors (excluding n and including 1). For example, 6 is a beautiful number since 6 = 1 + 2 + 3. Given an integer n as input write a program to print (i) all the proper divisors of n, (ii) is the number a prime or composite, and (iii) is the number a beautiful number or not. You are not allowed to use any loop in today’s program. Use recursion. Submit one (single) C/C++ program. Sample Output palash@palash-ThinkPad-X1-Yoga-3rd:~$ ./a.out Write n: 496 The proper divisors of 496 are 1, 2, 4, 8, 16, 31, 62, 124, 248, 496 is a composite number 496 is a beautiful number palash@palash-ThinkPad-X1-Yoga-3rd:~$ palash@palash-ThinkPad-X1-Yoga-3rd:~$ ./a.out Write n: 387 The proper divisors of 387 are 1, 3, 9, 43, 129, 387 is a composite number 387 is not a beautiful number palash@palash-ThinkPad-X1-Yoga-3rd:~$

Back to Lab Problems
Functions and Recursions/Arithmetic/Problem #5

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #5

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.