0% found this document useful (0 votes)
458 views3 pages

Program 5

The document outlines a C program designed to approximate the value of sin(x) using a series expansion method due to hardware limitations. It includes an algorithm detailing the steps to read an angle, compute the approximation, and display the result. The program has been successfully executed and verified for performance improvement.

Uploaded by

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

Program 5

The document outlines a C program designed to approximate the value of sin(x) using a series expansion method due to hardware limitations. It includes an algorithm detailing the steps to read an angle, compute the approximation, and display the result. The program has been successfully executed and verified for performance improvement.

Uploaded by

j11002179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

A sensor in a robotic arm needs to calculate the angle of rotation in real-time, but the

hardware doesn't support built-in trigonometric functions. Develop a C program to


approximate the value of sin(x) using a series expansion method for improved
performance.

Aim: To develop a C program to approximate the value of sin(x) using a series expansion
method for improved performance

Algorithm

Step 1: Start

Step 2: Read angle.

Step 3: Read number of terms n.

Step 4: Initialize

 term = x
 sum = x
 i=1

Step 5: Repeat until i < n

 Update term = (-term * x * x) / ((2 * i) * (2 * i + 1))


 Update sum = sum + term
 Increment i = i + 1

Step 6: Display sum as the approximated sin value.

Step 7: Stop

Program:

#include <stdio.h>

#include <math.h>

#define PI 3.14

#include<conio.h>

int main() {

int n, i;

float x, term, sum, degree;

clrscr();
printf("Enter the angle in degree: ");

scanf("%f", &degree);

x= (degree * PI)/180.0;

printf("Enter number of terms: ");

scanf("%d", &n);

term = x; // first term

sum = x;

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

term = (-term * x * x) / ((2 * i) * (2 * i + 1));

sum += term;

printf("Approximated sin(%.2f) = %.6f\n", x, sum);

getch();

return 0;

Flowchart:
Result:

The program to approximate the value of sin(x) using a series expansion method for
improved performance has been executed successfully and the output was verified.

You might also like