UNITED INTERNATIONAL UNIVERSITY (UIU)
Department of Computer Science and Engineering (CSE)
CLASS ASSIGNMENT SPRING, 2025
CSE 1111: Structured Programming Language
1. Check out the following code snippets:
int cnt = 0;
for(int i = 1; i <= n; i++)
{
if(n % i == 0) cnt++;
}
printf(”Number of divisors of %d is: %d\n”, n, cnt);
int sum = 0;
for(int i = 1; i < n; i++)
{
if(a % i == 0) sum += i;
}
printf(”Sum of proper divisors of %d is: %d\n”, n, sum);
int sum = 0;
for(int i = 1; i < n; i++)
{
if(a % i == 0) sum += i;
}
if(sum == n)
{
printf(”%d is a perfect number\n”, n);
}
else
{
printf(”%d is not a perfect number\n”, n);
}
Now, your task is to write a C program that prints all perfect numbers between 1 and 500.
Necessary Concepts:
� Divisor: A number b is a divisor of a if b is positive and dividing a by b results in 0 remainder
[a mod b = 0].
� Proper Divisor: A number b is a proper divisor of a if b is a divisor of a and b < a.
� Perfect Number: A number a is a perfect number if it is equal to the sum of its proper divisors.
CSE 1111 Page 1 of 1