C Programming

# C program to find sum of cosine series?

###### Wiki User

###### December 02, 2008 6:12AM

#include<stdio.h>

#include<math.h>

void main()

{

float pow = 2.0, nr, dr = 1.0, x1, sum;

int i = 1,n,s = -1,x;

clrscr();

printf("\n\n\t ENTER THE ANGLE...: ");

scanf("%d", &x);

x1 = 3.142 * (x / 180.0);

sum = 1.0;

nr = x1*x1;

printf("\n\t ENTER THE NUMBER OF TERMS...: ");

scanf("%d",&n);

while(i<=n)

{

dr = dr * pow * (pow - 1.0);

sum = sum + (nr / (dr * s));

s = s * (-1);

pow = pow + 2.0;

nr = nr * x1 * x1;

i++;

}

printf("\n\t THE SUM OF THE COS SERIES IS..: %0.3f", sum);

getch();

}

## Related Questions

###### Asked in C Programming

### A c program to generate a series of 1 3 6 10 15 21.?

As you can see, this series is the sum of the sequence: 1, 2, 3,
4, 5, 6.
That is to say:
1 + 2 = 3
3 + 3 = 4
6 + 4 = 10
10 + 5 = 15
15 + 6 = 21
To program this in C, you would want a simple incremental
counter which would be added to the series sum on each iteration of
the loop.
{
int c = 2;
int sum = 1;
// loop until you find all the numbers you want
while(1) {
// increase the running sum to find the next next number in the
series
sum += c;
// increment our counter
++c;
}
}

###### Asked in Java Programming, C Programming, Numerical Series Expansion

### Program to find the sum of harmonic series?

Let's assume that you want the sum of the general harmonic
series:
sum(n=0,inf): 1/(an+b)
Since we know that the harmonic series will converge to
infinity, we'll also assume that you want the sum from 0 to n.
double genHarmonic(const double n, const double a, const double
b) {
double sum = 0.0;
// perform calculations
int k;
for(k = 0; k <= n; ++k) {
sum += 1.0 / (a * k + b);
}
return sum;
}

###### Asked in C Programming

### Write a C program to find the cosine and sine series?

//COSINE SERIES
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,n,x;
float t,s;
clrscr();
printf("enter the value of x,n \n");
scanf("%d%d",&x,&n);
t=1;
s=1;
for(i=1;i<n;i++)
{
t=(-1)*((pow(x,2)*t*i))/((2*i)*((2*i-1)*i));
s=s+t;
printf("s=%6.2f & t=%6.2f\n",s,t);
}
printf("\n sum of the cos series=%5.2f\n",s);
}

###### Asked in C Programming, Java Programming

### How do you write a program to find the sum of n numbers in an array?

In Java: // This program adds all numbers in the array int sum =
0; for (int i = 0; i < myArray.length(); i++) { sum +=
myArray[i]; }
In Java: // This program adds all numbers in the array int sum = 0;
for (int i = 0; i < myArray.length(); i++) { sum += myArray[i];
}
In Java: // This program adds all numbers in the array int sum = 0;
for (int i = 0; i < myArray.length(); i++) { sum += myArray[i];
}
In Java: // This program adds all numbers in the array int sum = 0;
for (int i = 0; i < myArray.length(); i++) { sum += myArray[i];
}