Algorithm
- Start
- Read a number ‘n’ > 0
- Assign sum with 0, i with 1
- If i<=n then repeat steps (5) and (6) else go to (7)
- If modulus(n,i) = 0
then sum Ć sum + i and go to (6)
else go to (6)
- i Ć i + 1
- Print sum of factors of n is sum
- Stop
Program
#include <stdio.h>
main()
{
int n,i,sum ;
clrscr() ;
printf("\tProgram to find Sum of factors of a Number\n") ;
printf("\n Input\n\n") ;
printf("Enter a Number : ") ;
scanf("%d",&n) ;
sum = 0 ;
for (i=1;i<=n;i++)
if ((n%i) == 0)
sum += i ;
printf("\n Output\n\n") ;
if (n <= 0)
printf("Enter greater than Zero") ;
else
printf("Sum of factors of %d is : %d",n,sum) ;
getch() ;
}
Output
Program to find Sum of factors of a Number
Input
Enter a Number : 36
Output
Sum of factors of 36 is : 91
Program to find Sum of factors of a Number
Input
Enter a Number : 0
Output
Enter greater than Zero
No comments:
Post a Comment