Q.15 Write a 'C' program to add first seven terms of the following series using a for loop :
1/1! + 2/2! + 3/3! + ...... */ (AKTU. 2008 - 09)
Ans.
#include<stdio.h>
#include<conio.h>
#define terms 7
void main()
{
int i,j;
float product, sum = 0;
clrscr();
for(i = 1; i <= terms; i++)
{
product = 1;
for(j = 1; j <= i; j++)
product *= j;
sum += i/product;
}
printf("\n The sum of 1st %d terms of the series = %f\n",terms, sum);
printf("\nPress any key to exit.");
getch();
}
Q.16 Write a program in C to calculate the sum of the following series upto nth term.
F(x) = x1 - x3 + x5 - x7 +
............. (AKTU. 2010-11)
Ans.
/*Write a program in C to calculate the
sum of the following series upto
n - th term
F(x) = x^1 - x^3 + x^5 - x^7 + .....*/
#include<stdio.h>
#include<conio.h>
void main()
{
double x, term, sum = 0.0;
int i, n;
clrscr();
printf("\nEnter the value of x\n");
scanf("%lf", &x);
printf("\nEnter the number of terms\n");
scanf("%d", &n);
if( n >= 1)
{
term = x;
for( i = 0; i < n; i++)
{
sum = sum + term;
term = (-1 * x * x * term);
}
printf("\nSum = %lf", sum);
}
else
printf("\nSum = %lf", sum);
getch();
}
Q.17 Write a C program to calculate the sum of the following series upto 50 terms
SUM = -13 + 33 - 53 + 73 - 93 + 113 - ........ (AKTU. 2009-10)
Ans. /* Write a C program to calculate the sum of the following series upto 50 terms
SUM = -1^3 + 3^3 -5^3 + 7^3
at n =1 T(n) = -1
n =2 T(n) = 27
......
T(n) = (-1^n)*(2*n - 1)
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define n 50 /* number of terms */
void main()
{
double i, sum = 0;
clrscr();
printf("\nThe sum of the series");
printf("upto %d terms is: = ",n);
for(i = 1; i <= n; i++)
sum+= (pow(-1,i)) * (pow(((2*i) - 1),3));
printf("%.0lf ",sum);
getch();
}
Q.18 Write a program in C find sum S, of the following series. Using C language write the function to return the square root of numbers used in the series.
Ans.
# include <stdio.h>
# include <conio.h>
# include <math.h>
# define n 15
void main ()
{
double i, sum = 0;
clrscr ();
printf (“\ n The sum of the series”);
printf (“ upto % d term is : =”, n);
for (i = 1; i < = n ; i + = z)
sum + = pow (i, 1.5);
printf (“%. olf”, sum);
getch ();
}