Write a C program to find the perfect numbers within the Nth term.


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 nosum = 0n;

    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 = ni <= (no / 2); i++)

    {

        if (no % i == 0)

        {

            sum = sum + i;
        }
    }

    if (sum == no)

    {

        printf("%d is perfect number with a sum of %d "nosum);
    }

    else

    {

        printf("%d is not a perfect number with sum %d "nosum);
    }
}


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


Follow our page for regular updates.

0 Comments