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 (“...
https://www.computersprofessor.com/2016/06/program-for-calculate-sum-of-factors-of.html?m=0
# 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
|