DO NOT MISS

Ads

Sunday, 31 July 2016

Program 13 Using While loop



The sum of the factors of the given no. is equal to the twice of the given no. then the number is called Perfect no.

Ex:- 
Number 6 is Perfect Number
Number 6 Factors =1,2,3,6
1*6=6
2*3=6
3*2=6
6*1=6
1+2+3+6=12 (6+6)


#include<stdio.h> 
#include<conio.h> 

void main() 

       { 

              int n,i,sum=0; 
              clrscr(); 

              printf("enter a number:"); 
              scanf("%d",&n); 

              i=1; 
              while(i<=n)

                       { 

                            if(n%i==0) 
                            sum=sum+i; 
                            i++; 

                       } 

             if(sum==n*2) 
             printf("the number is perfect number\n"); 
             else 
             printf("the number is not perfect number"); 

             getch(); 

     }


Output:-

______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________




Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims