Functions and Recursions – Arithmetic – Problem #5
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
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:~$