C Language "Sum of 1+3+5+....+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 += 2) { sum += i; } printf("Sum of the series 1+3+5+...+%d = %d\n", n, sum); return 0; }Output:
Enter the value of n: 7
Sum of the series 1+3+5+...+7 = 16
Comments
Post a Comment