FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 37   



Following program shows you how to print sum of n natural numbers.
In this program we get number from user and shows sum of n natural numbers using following formula
Sum of n natural numbers = input X (input + 1)/2

#include <stdio.h>
int main() {
    int input;
    printf("Enter a number:");
    scanf("%d", &input);
    int result = input * (input + 1) / 2;
    printf("Sum of n natural numbers is: %d", result);
}

Output:

Enter a number: 6
Sum of n natural numbers is: 21



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News