Question
The Factor of a Given Number Using C-Program
Sample TestCase Expected Output
1. 1018
2. 1228
Answer
#include <stdio.h>int main() { int num, i, sum=0; scanf("%d", &num); for (i = 1; i <= num; ++i) { if (num % i == 0) sum += i; } printf("%d", sum); return 0;}
Explanation:
What is the factor in math?
Factor, in mathematics, a number or algebraic expression that divides another number or expression evenly—i.e., with no remainder. For example, 3 and 6 are factors of 12 because 12 ÷ 3 = 4 exactly and 12 ÷ 6 = 2 exactly. .This called Factors of a number...
Here sum += i defines sum = sum + i
sum = 0 + 1 = 1
sum = 1 + 2 = 3
sum = 3 + 5 = 8
sum = 8 + 10 = 18
This comment has been removed by a blog administrator.
ReplyDelete