954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

c code to check for a perfect number!!

#include<stdio.h>
int main()
 {

     int n,i,c=0;
     printf("\nEnter a no:");
     scanf("%d",&n);
     for(i=1;i<n;i++)
      {
          if(n%i==0)
           {
               c=c+i;
           }

      }

   if(n==c)
     printf("\nPerfect no.");
    else
      printf("\nNot a perfect no.");

 }
compzets
Newbie Poster
5 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

please specify what is the problem in the code .its running well.or your loop is not working properly?

neeraj goswami
Newbie Poster
13 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
#include<stdio.h>
    #include<conio.h>
    int main()
    {
     
    int n,i,c=0;
    printf("\nEnter a no:");
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
    if(n%i==0)
    {
    c=c+i;
    }
     
    }
     
    if(n==c)
      {printf("\nPerfect no.");getch();}
    else
      {printf("\nNot a perfect no.");getch();}
     
    }
compzets
Newbie Poster
5 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

And more terrible code... Please stop posting just to boost your ego.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

hey buddy if u r not aware of c programming language then pl dont visit this site...!!!

First learn c nd then dare to post on ma uploads....!!!

Go learn first champ...!!!

compzets
Newbie Poster
5 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

compzets:-
We are not here to check full codes if you are not specifying your problems.what do you want..??
positing the same code doesn't make a clear idea to us again about your problem.

SPECIFY YOUR AREA OF PROBLEM

hey buddy if u r not aware of c programming language then pl dont visit this site...!!!


you should check about the detail of person whom you used to say like this. seems to be you are a newbie.First learn c nd then dare to post on ma uploads....!!!
you don't ve much idea about the basics of C..google the standards of C and first learn them.Go learn first champ...!!!
yep you are right...go learn first champ...!!

now to your programming part.. #include
not a recognized file or directory in gcc compliers..

please stop using getch() it's not in use for any gcc compilers.
its terrible to use getch() now.

cse.avinash
Junior Poster
191 posts since Feb 2011
Reputation Points: 10
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: