C Language "Sum of 1+2+.....+n series using for loop" program with output

 #include <stdio.h>

int main() { int n, sum = 0; printf("Enter the value of n: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { sum += i; } printf("Sum of 1 + 2 + ... + %d = %d\n", n, sum); return 0; }




Output:
Enter the value of n: 5 Sum of 1 + 2 + ... + 5 = 15

Comments

Popular posts from this blog

Video Formats

Where video editing is used

File saving and folder management