QUESTION:- Write a C program to find the perfect numbers within the Nth term.
Test Data :
Input the starting range or number: 1
Input the ending range of number: 50
Expected Output :
The Perfect numbers within the given range: 6 28
#include <stdio.h>
#include <conio.h>
void main()
{
int no, sum = 0, n;
printf("enter a value to satrt a perfect number: ");
scanf("%d", &n);
printf("enter a value to end up the percet number: ");
scanf("%d", &no);
for (int i = n; i <= (no / 2); i++)
{
if (no % i == 0)
{
sum = sum + i;
}
}
if (sum == no)
{
printf("%d is perfect number with a sum of %d ", no, sum);
}
else
{
printf("%d is not a perfect number with sum %d ", no, sum);
}
}
OUTPUT
enter a value to start a perfect number: 5
enter a value to end up the percent number: 60
60 is not a perfect number with a sum of 98
0 Comments