Sum of Natural Numbers
Submit solution
C
Points:
5 (partial)
Time limit:
8.0s
Memory limit:
64M
Author:
Problem type
Allowed languages
Problem Statement
Given an integer N, find the sum of natural numbers till N
Sample Input
5
Sample Output
15
Comments
include<stdio.h>
include<conio.h>
int main() { int n,i,sum=0; printf("Enter the range : "); scanf("%d",&n); for(int i=1; i<=n; i++) { sum += i; } printf("The sum is : %d",sum); return 0; }
include<stdio.h>
int main() { int i,n,sum=0; scanf("%d",&n); for(i=0;i<=n;i++) { sum=sum+i; } printf("%d",sum);
return 0;
}