Problem Description
Dolu have a homework to find sum of factors of a given number. Use C language to solve Dolus Problem
CODING
ARENA::
#include
<stdio.h>
int
main()
{
int sum,n=1,a;
scanf("%d",&a);
if(a==0)
printf("0");
while(n<=a)
{
if(a!=0 && a%n==0)
{
printf("%d ",n);
sum=sum+n;
}
n=n+1;
}
printf("\nSum=%d",sum);
return 0;
}
Test Case 1
Input (stdin)
25
Expected
Output
1 5 25
Sum=31
Test Case 2
Input (stdin)
45
Expected
Output
1 3 5 9 15 45
Sum=78
No comments:
Post a Comment