0% found this document useful (0 votes)
10 views1 page

sinCosSeriesValue

Code for sin cos series

Uploaded by

nayanafranco111
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)
10 views1 page

sinCosSeriesValue

Code for sin cos series

Uploaded by

nayanafranco111
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/ 1

29/12/2023, 21:43 sinCosSeriesValue.

VSCode Projects\C\Codes\Sine-Cos-Series\sinCosSeriesValue.c

1 #include <stdio.h>
2 #include <math.h>
3
4 float fact(int n) {
5 if (n == 0 || n == 1)
6 return 1;
7 else
8 return n * fact(n - 1);
9 }
10
11 float calculateSin(float x, int terms) {
12 float res = 0;
13 for (int i = 0; i < terms; i++)
14 res += pow(-1, i) * pow(x, 2 * i + 1) / fact(2 * i + 1);
15 return res;
16 }
17
18 float calculateCos(float x, int terms) {
19 float res = 0;
20 for (int i = 0; i < terms; i++)
21 res += pow(-1, i) * pow(x, 2 * i) / fact(2 * i);
22 return res;
23 }
24
25 int main() {
26 float x;
27 int n;
28 printf("Enter the value of x (degrees): ");
29 scanf("%f", &x);
30 float rad = x * (3.141592 / 180);
31 printf("Enter the number of terms: ");
32 scanf("%d", &n);
33 printf("sin(%.3f) = %.3f\n", x, calculateSin(rad, n));
34 printf("cos(%.3f) = %.3f\n", x, calculateCos(rad, n));
35 return 0;
36 }
37

localhost:60795/3a2594da-2065-4dc9-97b5-69034fca5b9e/ 1/1

You might also like