Sum of n numbers – C Program


Write a C program to find the sum of n numbers given as input by the user. [June 2015, Set-1]

#include <stdio.h>

int main()
{
    int i, n, sum = 0;
    
    printf("Enter an integer :");
    scanf("%d", &n);

    for (i = 1; i <= n; i++)
    {
        sum += i;
    }

    printf("The sum of the %d numbers is %d.", n, sum);
    
    return 0;
}