It is easy to get sum of series 1 + 3 + 5 + 7 + . . . + n in C program. In this tutorial, I’ll show you how to do it in easy way in C program. Here is a simple code for it:
printf("Enter the value of n of the series: ");
printf("Sum of the series: ");
for (i =1; i <= n; i=i+2)
printf("%d = %d ",i,s);
printf("%d + ",i);
Enter the value of n of the series: 10
Sum of the series: 1 + 3 + 5 + 7 + 9 = 25
In above code, I have sum up the series with a equation first. Then, I have tried to show number, plus sign, result and in a word equation by iterating from 1 to n using for loop.
In this tutorial, I have shown how to get sum of series 1 + 3 + 5 + 7 +…. + n in C Program. Hope you have enjoyed the tutorial. If you want to get updated, like the facebook page http://www.facebook.com/freetechtrainer and stay connected.