Add first n natural numbers


Submit solution

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

Author:
Problem type
Allowed languages
C

To add first n natural numbers

Sample input

5

Sample Output

15

Sample input

0

Sample output

0

Sample input

-5

Sample output

0


Comments


  • 0
    RAJESHCB  commented on April 14, 2023, 3:34 p.m.

    include <stdio.h>

    int main() { int n, i, sum = 0;

    scanf("%d", &n);
    
    for (i = 1; i <= n; ++i) {
        sum += i;
    }
    
    printf("Sum = %d", sum);
    return 0;

    }