0% found this document useful (0 votes)
4 views1 page

C Program for Finding Perfect Numbers

The document is an assignment for a CSE course at United International University, focusing on structured programming in C. It includes code snippets for counting divisors, summing proper divisors, and checking for perfect numbers. The task is to write a C program that identifies all perfect numbers between 1 and 500.

Uploaded by

Redwan Ahmed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

C Program for Finding Perfect Numbers

The document is an assignment for a CSE course at United International University, focusing on structured programming in C. It includes code snippets for counting divisors, summing proper divisors, and checking for perfect numbers. The task is to write a C program that identifies all perfect numbers between 1 and 500.

Uploaded by

Redwan Ahmed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like