Introduction To C Lab 6 and 7 Programs Given by Professor Muralidharan Sir
Introduction To C Lab 6 and 7 Programs Given by Professor Muralidharan Sir
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