Write c program to accept the numbers from user store all perfect number in an array and display the array

#include<stdio.h>
#include<conio.h>
void main()
{
int p[50],i,j,k=0,n,sum=0;
clrscr();
printf("\n enter the limit\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
sum=0;
for(j=1;j<i;j++)
if(i%j==0)
sum=sum+j;
if(sum==i)
{
p[k]=i;
k++;
}
}
printf("\n display perfect no");
for(i=1;i<k;i++)
{
printf("\n%d",p[i]);
}
getch();
}

Comments