Cosine Series

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

COSINE SERIES

EX .NO:
DATE:
COSINE SERIES

AIM :

To write a program to print the cosine series.

ALGORITHM:

Step-1 start

Step-2 initialize n 20;

Step-3 Read x

Step-4 convert x values into radian using formula x x*3.1412 / 180

Step-5 t 1, sum 1

Step-6 setup for loop from i 1 until (i<n+1) increment i

Step-7 t (t*(pow(double)(-1), (double)(2*i-1))8x*x/(2*i*(2*i-1))

Step-8 sum sum + t

Step-9 print sum

Step-10 stop

PSEUDOCODE :

1. Begin the program by initializing n


2. Read x
3. Convert x into radian using formula
4. Setup for loop
5. Print sum
6. Terminate the program

Courtesy Ms. P. Chitra, Assistant Professor. Page 1


COSINE SERIES

FLOW CHART
start

Read x

a=x

x = x *3.1412 / 180

temp = 1

sum = 1

for i = 1; i < no+ 1; i++

temp = temp *pow((double)(-1),(double)(2*i-1))

* x * / (2 *I *(2 * I 1))

sum = sum + temp

Print a, sum

stop

Courtesy Ms. P. Chitra, Assistant Professor. Page 2


COSINE SERIES

PROGRAM :

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

float x, a, sum, temp;

int i, no = 20, mul;

clrscr();

printf(\n enter the value of x : );

scanf(%f, &x);

a = x;

x = x*3.1412 / 180;

temp = 1;

sum = 1;

for(i = 1; i < no + 1; i++)

temp = temp *pow((double)(-1),(double)(2 * I 1)) * x * x / (2 * I * (2 * I -1));

Courtesy Ms. P. Chitra, Assistant Professor. Page 3


COSINE SERIES

sum = sum + temp;

printf(\n the cosine value of %f is %f, a , sum);

getch();

OUTPUT :

Enter the value of x : 60

The cosine value of 60.000000 is 0.500113

Courtesy Ms. P. Chitra, Assistant Professor. Page 4


COSINE SERIES

RESULT:

The program is executed and the output is verified.

Courtesy Ms. P. Chitra, Assistant Professor. Page 5

You might also like