Subscribe

RSS Feed (xml)

Friday, February 20, 2009

Write a C program to calculate the sum of factors of a number.

#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
void main( )
{
int no, sum=0, x;
clrscr( );
printf("Enter the required number :");
scanf("%d", &no);
for( x=1; x<=no; x++) {
if(no%x==0) sum=sum+x;
}
printf("\nSum of the factors of %d is: %d", no, sum);
getch( );
}

Output:-
Enter the required number: 10

Sum of the factors of 10 is: 18.
ie., 1+2+5+10 =18

Note:- If u have any doubt regarding this program or logic, please feel free to contact me.

10 comments:

  1. chutiya algo hai yeh...

    ReplyDelete
  2. i would like to listen c programme classes online will u plzzzz help me

    ReplyDelete
  3. Replies
    1. Could you please explain, why you think the above program is not good.
      RSVP.

      Delete
    2. Could you please explain, why you think the above program is not good.
      RSVP.

      Delete
    3. Could you please explain, why you think the above program is not good.
      RSVP.

      Delete
  4. A program to check whether the sum of factors is even or odd

    ReplyDelete
  5. I have not get the output properly

    ReplyDelete
  6. The logic or program both are easy. And it is easy to understand.

    ReplyDelete