Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

perfect numbers in c

/* C Program to find Perfect Number using For Loop */

# include <stdio.h>   

int main()   
{   
 int i, Number, Sum = 0 ;   
  
 printf("
 Please Enter any number 
") ;   
 scanf("%d", &Number) ;   
 
 for(i = 1 ; i < Number ; i++)   
  {   
   if(Number % i == 0)   
     Sum = Sum + i ;   
  }    

 if (Sum == Number)   
    printf("
 %d is a Perfect Number", Number) ;   
 else   
    printf("
%d is not the Perfect Number", Number) ;   

return 0 ;   
}
Source by www.tutorialgateway.org #
 
PREVIOUS NEXT
Tagged: #perfect #numbers
ADD COMMENT
Topic
Name
6+7 =