Skip to main content

Sum of 'n' natural numbers

#include <stdio.h> int main() { int n, sum = 0; printf("Enter the value of n : "); scanf("%d" , &n ); printf("\n"); for(int i = 1 ; i <= n; i++ ) { sum = sum + i; } printf("The sum of %d natural numbers is %d", n, sum); }




Comments