answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<math.h>

void main()

{

int i = 2, n, s = 1, x, pwr = 1, dr;

float nr = 1, x1, sum;

clrscr();

printf("\n\n\t ENTER THE ANGLE...: ");

scanf("%d", &x);

x1 = 3.142 * (x / 180.0);

sum = x1;

printf("\n\t ENTER THE NUMBER OF TERMS...: ");

scanf("%d", &n);

while(i <= n)

{

pwr = pwr + 2;

dr = dr * pwr * (pwr - 1);

sum = sum + (nr / dr) * s;

s = s * (-1);

nr = nr * x1 * x1;

i+= 2;

}

printf("\n\t THE SUM OF THE SINE SERIES IS..: %0.3f",sum);

getch();

}

To get all source codes for calculating sine,cose and tan through Taylor series in C++, visit:

http://bitsbyta.blogspot.com/2011/02/calculating-sine-in-radians-using_16.HTML

http://bitsbyta.blogspot.com/2011/02/calculating-cosine-in-radians-using.HTML

http://bitsbyta.blogspot.com/2011/02/calculating-tan-in-radians-using-Taylor.HTML

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

// from Pondicherry

#include
#include
void main()
{
int i = 2, n, s = 1, x, pwr = 1, dr=1;
float nr = 1, x1, sum;
clrscr();
printf("\n\n\t ENTER THE ANGLE...: ");
scanf("%d", &x);
x1 = 3.14159 * (x / 180.0);
sum = x1;
nr = x1;
printf("\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d", &n);
while(i <= n)
{ s = s * (-1);
nr = nr * x1 * x1;
pwr = pwr + 2;
dr = dr * pwr * (pwr - 1);
sum = sum + ((float)nr / dr) * s;
i++;
}
printf("\n\t THE SUM OF THE SINE SERIES IS..: %0.3f",sum);
getch();
}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

/*

Practical C Programming, Third Edition

By Steve Oualline

Third Edition August 1997

ISBN: 1-56592-306-5

Publisher: O'Reilly

*/

/* Usage: *

* sine *

* *

* is an angle in radians *

* *

* Format used in f.fffe+X *

* *

* f.fff is a 4 digit fraction *

* + is a sign (+ or -) *

* X is a single digit exponent *

* *

* sine(x) = x - x**3 + x**5 - x**7 *

* ----- ---- ---- . . . . *

* 3! 5! 7! *

* *

* Warning: This program is intended to show some of *

* problems with floating point. It not intended *

* to be used to produce exact values for the *

* sin function. *

* *

* Note: Even though we specify only one-digit for the *

* exponent, two are used for some calculations. *

* This is due to the fact that printf has no *

* format for a single digit exponent. *

*/

#include

#include

#include

/*

* float_2_ascii -- turn a floating-point string *

* into ascii. *

* *

* Parameters *

* number -- number to turn into ascii *

* *

* Returns *

* Pointer to the string containing the number *

* *

* Warning: Uses static storage, so later calls *

* overwrite earlier entries *

*/

static char *float_2_ascii(floatnumber)

{

static char result[10]; /*place to put the number */

sprintf(result,"%8.3E", number);

return (result);

}

/*

* fix_float -- turn high precision numbers into *

* low precision numbers to simulate a *

* very dumb floating-point structure. *

* *

* Parameters *

* number -- number to take care of *

* *

* Returns *

* number accurate to 5 places only *

* *

* Note: This works by changing a number into ascii and *

* back. Very slow, but it works. *

*/

float fix_float(float number)

{

float result; /* result of the conversion */

char ascii[10]; /* ascii version of number */

sprintf(ascii,"%8.4e", number);

sscanf(ascii, "%e", &result);

return (result);

}

/*

* factorial -- compute the factorial of a number. *

* *

* Parameters *

* number -- number to use for factorial *

* *

* Returns *

* factorial(number) or number! *

* *

* Note: Even though this is a floating-point routine, *

* using numbers that are not whole numbers *

* does not make sense. *

*/

float factorial(float number)

{

if (number <= 1.0)

return (number);

else

return (number *factorial(number - 1.0));

}

int main(int argc, char *argv[])

{

float total; /* total of series so far */

float new_total;/* newer version of total */

float term_top;/* top part of term */

float term_bottom;/* bottom of current term */

float term; /* current term */

float exp; /* exponent of current term */

float sign; /* +1 or -1 (changes on each term) */

float value; /* value of the argument to sin */

int index; /* index for counting terms */

if (argc != 2) {

fprintf(stderr,"Usage is:\n");

fprintf(stderr," sine \n");

exit (8);

}

value = fix_float(atof(&argv[1][0]));

total = 0.0;

exp = 1.0;

sign = 1.0;

for (index = 0; /* take care of below */ ; ++index) {

term_top = fix_float(pow(value, exp));

term_bottom = fix_float(factorial(exp));

term = fix_float(term_top / term_bottom);

printf("x**%d %s\n", (int)exp,

float_2_ascii(term_top));

printf("%d! %s\n", (int)exp,

float_2_ascii(term_bottom));

printf("x**%d/%d! %s\n", (int)exp, (int)exp,

float_2_ascii(term));

printf("\n");

new_total = fix_float(total + sign * term);

if (new_total == total)

break;

total = new_total;

sign = -sign;

exp = exp + 2.0;

printf(" total %s\n", float_2_ascii(total));

printf("\n");

}

printf("%d term computed\n", index+1);

printf("sin(%s)=\n", float_2_ascii(value));

printf(" %s\n", float_2_ascii(total));

printf("Actual sin(%G)=%G\n",

atof(&argv[1][0]), sin(atof(&argv[1][0])));

return (0);

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Function sin in header math.h

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Sine series program using c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to find the sum of sine series?

Writing a program for a sum of sine series requires a rather long formula. That formula is: #include #include #include main() { int i,n,x; .


How do you calculate sine value without using math function?

Using its Taylor-series.


When was Sine Language created?

Sine Language was created in 2009.


How to generate multi component sine wave signal by using matlab program?

Generating Sine and Cosine Signals (Use updated lab)


Fourier series of sine wave?

The fourier series of a sine wave is 100% fundamental, 0% any harmonics.


How do you calculate arc sine?

arc sine is the inverse function of the sine function so if y = sin(x) then x = arcsin(y) where y belongs to [-pi/2, pi/2]. It can be calculated using the Taylor series given in the link below.


Half range sine and cosine series?

half range cosine series or sine series is noting but it consderingonly cosine or sine terms in the genralexpansion of fourierseriesfor examplehalf range cosine seriesf(x)=a1/2+sigma n=0to1 an cosnxwhere an=2/c *integral under limits f(x)cosnxand sine series is vice versa


How do you say garland in sign language?

how do you say hi in sine language


When you enter a sine into your calculator and press the arc sine key you get the answer but how does your calculator convert sine into degrees?

General answer: Math Specific Answer: Taylor Series


What are the top communication in the world?

sine language, moscode and mail


What is the Fourier Series for x sinx from -pi to pi?

The word sine, not sinx is the trigonometric function of an angle. The answer to the math question what is the four series for x sine from -pi to pi, the answer is 24.3621.


What is a good sentence using the word sine die?

The court will take a break without sine die.