Find perfect number between 1 to 50

#include<stdio.h>
#include<conio.h>
void main()
{
void perfect();
clrscr();
perfect();
getch();
}
void perfect()
{
int n,i,s,lim;
lim=1;
while(lim<=50)
{
i=1;s=0;
while(i<lim)
{
if(lim%i==0)
{
s=s+i;
}
i++;
}
if(s==lim)
printf("perfect no =%d\n",lim);
lim++;
}
}

Comments

  1. sir could you please tell us how do you write it in deatail it will be helpful to me i am in mca ist sem and this programming goes out of my mind please help!

    ReplyDelete
    Replies
    1. I also Pursuing MCA 1st Sem. at IGNOU. this Program have in C programming Assignment.
      Nice Post

      Delete
    2. This comment has been removed by the author.

      Delete
    3. i m getting, while(i<lim)
      statement missing error
      please reply asap..

      Delete
  2. this program is not showing any output will u help me

    ReplyDelete
  3. this program is haivng a error in it!!!!!!!!

    ReplyDelete
  4. #include
    int main(){
    int n,i,sum;

    printf("Perfect numbers are: ");
    for(n=1;n<=50;n++){
    i=1;
    sum = 0;

    while(i<n){
    if(n%i==0)
    sum=sum+i;
    i++;
    }

    if(sum==n)
    printf("%d ",n);
    }

    return 0;
    }

    Output:
    Perfect numbers are: 6 28

    ReplyDelete
    Replies
    1. have u used function for this

      Delete
    2. there is no function in this...

      jst define perfect() function in main()

      and paste all code in the perfect()

      thats it....

      Delete
  5. The program is having an error at line 4.

    ReplyDelete

Post a Comment