Perfect Number in C || while loop || C programming

This is a program of while loop in which we are going to find Perfect Number with the help of the C Programming language.

 

#include <stdio.h>
void main()
{
    int n, i, sum;
    int mn, mx;
    printf("Enter the start point : ");
    scanf("%d", &mn);
    printf("Enter the end point : ");
    scanf("%d", &mx);
    printf("The Perfect numbers from the range are :");
    for (n = mn; n <= mx; n++)
    {
        i = 1;
        sum = 0;
        while (i < n)
        {
            if (n % i == 0)
                sum = sum + i;
            i++;
        }
        if (sum == n)
            printf("%d ", n);
    }
    printf("\n");
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post