Problem: Program to find sum of N natural numbers.
Given a number, n, you need to find sum all numbers from 1 to n.
#include<stdio.h>
int main() {
int n, sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum += i;
}
printf("%d\n",sum);
return 0;
}
int main() {
int n, sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum += i;
}
printf("%d\n",sum);
return 0;
}