WAP to Calculate the sum of given Series by using do-while loop or Statement

Engg.... | 23:55 | | Best Blogger Tips
Statement of C Program: This Program prints the sum of the following Series:

Mathematical Series

#include<stdio.h>
#include<conio.h>
void main()
{
int n , sign , term_cont;
float term , num , den , sum;
clrscr();
sum=0;
printf(" Enter the number of terms in the series\n");

scanf("%d" , &n);
sign = 1;
num = 1;
den = 1;
term_cont = 1;
do
{
term = (num/den) * sign;
sum + = term;
den ++;
sign* = (-1);                                              /*  sign = sign * (-1)   */
term_cont ++;
} while (term_cont<=n);
printf(" Sum of the series = %f\n" , sum);
}                                                                /* End of main() */

Output:
Enter the number of terms in the series
4
Sum of the series = 0.58

                                                                   That's All
Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

0 comments:

Post a Comment