WRITE A Q BASIC PROGRAM ON THE TOPIC - TO ADD NATURAL NUMBERS FROM 1 TO 20
Answers
Answered by
2
Answer:
The positive numbers 1, 2, 3... are known as natural numbers. The sum of natural numbers up to 10 is:
sum = 1 + 2 + 3 + � + 10
Sum of Natural Numbers Using for Loop
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
sum += i;
}
printf("Sum = %d", sum);
return 0;
}
Explanation:
hope it help mark as brain least
Similar questions
Social Sciences,
7 months ago
Math,
7 months ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago