Sum of first N natural numbers


Submit solution

Points: 10 (partial)
Time limit: 8.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C

Problem statement

Given a positive integer N as input, print the sum of first N natural numbers.When N is less than or equal to 0, 0 should be printed.

Sample Input

5

Sample Output

15

Explanation

Sum of first 5 natural numbers 1+2+3+4+5=15


Comments


  • 0
    kunisetti_nishnath  commented on May 4, 2023, 3:12 p.m.

    include<stdio.h>

    int main() { int sum=0,i=5; while(i<=5) { sum=sum+1; } printf("%d",sum); }