Saturday 11 August 2012

Loop control structure020


Input a number and print all the factors of that number and sum of the factors.


#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;
                    
        }
        printf ("\n\t SUM = %d", sum);
        getch ( );
}


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...