Computer Science, asked by purkait996, 8 months ago

3)write a program to print the summation of natural numbers from 1 to n.. n will be given by user​

Answers

Answered by bulichaudhuri890
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