XMPP JavaScript Library

Program to check whether given number is a perfect number or not

A number is a perfect number if it is equal to sum of all of it's positive divisors excluding itself

1 /*Programme to check whether a given number is a perfect number or not*/
2 #include <stdio.h>
3 #include <conio.h>
4 void main()
5 {
6 int num,i,sum=0;
7
8 printf("Enter a Number to chech it's perfection and 0 to quit: ");
9 scanf("%d",&num);
10
11 /*If vlaue entered by user is greater than 0 then continue else exit*/
12 while(num!=0)
13 {
14 /*Calculate the sum of all the positive divisors*/
15 for(i=1; i<num; i++)
16 {
17 if(num%i==0)
18 {
19 printf("%d + ",i);
20 sum=sum+i;
21 }
22 }
23 /*Check if the sum=num*/
24 if(num==sum)
25 {
26 printf("= %d",sum);
27 printf("Perfet Number");
28 }
29 else
30 {
31 printf("= %d",sum);
32 printf("Not a perfet Number");
33 }
34 sum=0;
35 printf("Enter a Number to chech it's perfection and 0 to quit: ");
36 scanf("%d",&num);
37 }
38 }
39
Add Your Comment
   
    Yes! I want to receive all comments by email

  by shilakant jha on 18-Aug-2012 01:06 pm
thanks
  • Reply
  •  1 Like
  •  3 Dislike
  • Report
  by Hari Prakash Tiwari on 13-Jun-2012 12:39 pm
nice programing concept.clear and neat post
  • Reply
  •  5 Like
  •  4 Dislike
  • Report

Warning: include(ads/adbrite_300_250.php): failed to open stream: No such file or directory in /home2/sachinpu/public_html/pages/algorithm.php on line 33

Warning: include(ads/adbrite_300_250.php): failed to open stream: No such file or directory in /home2/sachinpu/public_html/pages/algorithm.php on line 33

Warning: include(): Failed opening 'ads/adbrite_300_250.php' for inclusion (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home2/sachinpu/public_html/pages/algorithm.php on line 33

About the author

Sachin Puri Hi, I am Sachin Puri, I am a Programmer. Programming is my work and it is the thing i like to do most in my free time.
You can catch Sachin Puri at