A Program to find out the perfect number using c program

23 July 20110 comments

         #include<stdio.h>
int main()
{
         int n,i=1,sum=0;
         printf("\nEnter a number:-");
         scanf("%d",&n);
         while(i<n)
        {
                  if(n%i==0)
                  sum=sum+i;
                  i++;
        }
        if(sum==n)
              printf("\nThe no %d is a perfect number",i);
       else
              printf("\nThe no %d is not a perfect number",i);
        return 0;
}

OUTPUT:
Enter a number:-
6

The number 6 is a perfact number!_
Share this article :

Post a Comment

 
Support : All Quiz | Feedsoo | Daily Articles
Copyright © 2011. All Compiler - All Rights Reserved
Template Created by Freemium Themes Published by Enet Blog
Managed By Deep Kaur