Monday 13 August 2012

Loop control structure021


Input a number and determin that it is a perfect number or not.

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

void main ( )
{
        int           a, b, c, sum = 0;
        clrscr ( );
                         
        printf ("\n\t Enter a number......:"); scanf ("%d", &a);
        printf("\n\t Factors are..:");
                     
        for ( b = 1; b < a; b++ )

        {                                   
                         c = a % b;
                         if ( c == 0)
                         {            
                                   printf ("%d, ", b);
                                   sum = sum + b;
                         }
        }                       
        if ( a == sum)
                  printf ("\n\t The number is a perfect number");
        else             
                  printf ("\n\t The number is not a perfect number");
        getch ( );
}

Click here to contact us


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...