Write a 'C' Program to accept 'n' numbers, store all perfect numbers in an array and display this array.


#include

void main()
{
    int perf[100],limit,num,i,j,sum,k = 0;
    clrscr();
    printf("HOW MANY NUMBERS::>\n");
    scanf("%d",&limit);
    for(i = 0 ; i < limit ; i++)
    {
        printf("ENTER ANY NUMBER :: >");
        scanf("%d",&num);
        sum = 0;
        for(j = 1 ; j < num ; j++)
        {
            if(num % j == 0)
            {
                sum = sum + j;
            }
        }
        if(num == sum)
        {
            perf[k] = num;
            k++;
        }
    }
    printf("\nPERFECT NUMBERS ARE ::> \n");
    for(i = 0 ; i < k ; i++)
    {
        printf("%d ",perf[i]);
    }
    getch();
}
/*OUTPUT::
HOW MANY NUMBERS::>
5
ENTER ANY NUMBER :: >9
ENTER ANY NUMBER :: >26
ENTER ANY NUMBER :: >28
ENTER ANY NUMBER :: >6
ENTER ANY NUMBER :: >52

PERFECT NUMBERS ARE ::>
28 6
*
Write a 'C' Program to accept 'n' numbers, store all perfect numbers in an array and display this array. Write a 'C' Program to accept 'n' numbers, store all perfect numbers in an array and display this array. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.