0% found this document useful (0 votes)
18 views2 pages

Introduction To C Lab 6 and 7 Programs Given by Professor Muralidharan Sir

The document provides lab programs for computing the cosine and sine of an angle using Taylor series approximation. Lab Program 6 computes cos(x) and compares it with the built-in function, while Lab Program 7 computes sin(x) similarly. Both programs include C code examples and sample outputs for specified inputs.

Uploaded by

angelotommy006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Introduction To C Lab 6 and 7 Programs Given by Professor Muralidharan Sir

The document provides lab programs for computing the cosine and sine of an angle using Taylor series approximation. Lab Program 6 computes cos(x) and compares it with the built-in function, while Lab Program 7 computes sin(x) similarly. Both programs include C code examples and sample outputs for specified inputs.

Uploaded by

angelotommy006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

INTRODUCTION TO C PROGRAMMING

LAB PROGRAMS
The following is the syntax of lab 6 and 7 programs given by professor Muralidharan sir

LAB PROGRAM 6
Compute cos(x) using Taylor series approximation. Compare you result
with the built-in library function. Print both the results with appropriate inferences.

#include <stdio.h>
int main()
{
int n,i;
float sum,x,dx,term;
printf("Input number of terms\n");
scanf("%d",&n);
printf("Input angle in degrees\n");
scanf("%f",&dx);
x=dx*(3.14/180);
sum=1;
term=1;
for(i=1;i<=n;++i)
{
term=-(x*x)/((2*i-1)*(2*i))*term;
sum=sum+term;
}
printf("Sum of series cos(%f)=%f",dx,sum);
}

Output:
Input number of terms
10
Input angle in degrees
60
Sum of series cos(60.000000)=0.500460
LAB PROGRAM 7
Compute sin(x) using Taylor series approximation. Compare you result with the
built-in library function. Print both the results with appropriate inferences. Sine
function using
Taylor Series.
#include <stdio.h>
int main()
{
int n,i;
float sum,x,dx,term;
printf("Input number of terms\n");
scanf("%d",&n);
printf("Input angle in degrees\n");
scanf("%f",&dx);
x=dx*(3.14/180);
sum=x;
term=x;
for(i=1;i<=n;++i)
{
term=-(x*x)/((2*i+1)*(2*i))*term;
sum=sum+term;
}
printf("Sum of series sin(%f)=%f",dx,sum);
}

Output:
Input number of terms
10
Input angle in degrees
30
Sum of series sin(30.000000)=0.499770

You might also like