3)write a program to print the summation of natural numbers from 1 to n.. n will be given by user
Answers
Answered by
2
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;
}
Similar questions
Computer Science,
4 months ago
Math,
4 months ago
English,
8 months ago
Math,
1 year ago
Science,
1 year ago