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++;
}
}
#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++;
}
}
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!
ReplyDeleteI also Pursuing MCA 1st Sem. at IGNOU. this Program have in C programming Assignment.
DeleteNice Post
This comment has been removed by the author.
Deletei m getting, while(i<lim)
Deletestatement missing error
please reply asap..
output show this program
ReplyDeletePerfect No=6
ReplyDeletePerfect No=28
this program is not showing any output will u help me
ReplyDeletethis program is haivng a error in it!!!!!!!!
ReplyDelete#include
ReplyDeleteint 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
have u used function for this
Deletethere is no function in this...
Deletejst define perfect() function in main()
and paste all code in the perfect()
thats it....
The program is having an error at line 4.
ReplyDelete