Program for calculate sum of Factors of a given number

# include<stdio.h> #include<conio.h> main (  ) { int x, i = 1, sum = 0; printf (“enter a number”); scanf (“...

# include<stdio.h>
#include<conio.h>
main (  )
{
int x, i = 1, sum = 0;
printf (“enter a number”);
scanf (“%d”, &x);
while (i < = x)
{
 if (x % i = = 0)
 {
   sum = sum + i ;
   printf (“\n %d is a factor \n”, i);
  }
  i ++;
}          
printf (“\n sum of factors is % d”, sum);
getch();
}

Out put:

Enter a number 6
1 is a factor
2 is a factor
3 is a factor
6 is a factor

Related

C Programs 7549555790025004710

Post a Comment

emo-but-icon

item