SlideShare a Scribd company logo
#include
#include
#include
#include
//FIND FACTORIAL
double fact(int n)
{
int i;
double prod = 1.;
for(i = 1; i <= n; i++)
prod = prod * i;
return prod;
}
//FIND x TO THE POWER OF n
double pow(double x, int n)
{
int i;
double prod = 1.;
for (i = 0; i < n; i++)
prod = prod * x;
return prod;
}
//CALCULATE SIN(x)
double sineFun(double x)
{
double sum = 0.;
int i, sign = 1;
for (i = 0; i < 21; i++) {
sum = sum + sign * pow(x, 2 * i + 1) / fact(2 * i +1);
sign = -sign;
}
return sum;
}
//FUNCTION TO FIND COS(X) USING TAYLOR’S SERIE
double coseFun(double x)
{
}
//FUNCTION TO FIND EXP(X) USING TAYLOR’S SERIES
double expoFun(double x)
{
}
int main() {
double x;
char more;
do {
printf(" tttInput X: ");
scanf("%lf", &x);
printf(" tttt LibraryResult t MyResult");
printf(" tt sin( %.1lf)t %lft%lf", x, sin(x), sineFun(x));
printf(" tt cos( %.1lf)t %lft%lf", x, cos(x), coseFun(x));
printf(" tt exp( %.1lf)t %lft%lf", x, exp(x), expoFun(x));
printf("  ttttDo more (Y/N)?:");
scanf(" %s", &more);
}while(more=='y'||more=='Y');
} Turbo C-tc Input : 2.4 sin cos( 2.40) exp 2.4 LibraryResult 0.675463 -6.737394 11.823176
MyResult 0.675463 0.737394 11.823176 Do nore Y/N? y Input x: -2.4 MyResult -0.675463 -
0.737394 0.090218 LibraryResult sin? y Input x: 4.4 LibraryRe sult MyResult sin? y Input : 4.4
sin
Solution
Please find the required methods along with its output. Please see the comments against each line
to understand the step.
NOTE: while compiling please use the option -lm to avoid undefined reference error.
command : gcc -o main *.c -lm
#include
#include
#include
#include
#define PI 3.1415
//FIND FACTORIAL
double fact(int n)
{
int i;
double prod = 1.;
for(i = 1; i <= n; i++)
prod = prod * i;
return prod;
}
//FIND x TO THE POWER OF n
double power(double x, int n)
{
int i;
double prod = 1.;
for (i = 0; i < n; i++)
prod = prod * x;
return prod;
}
//CALCULATE SIN(x)
double sineFun(double x)
{
double sum = 0.;
int i, sign = 1;
for (i = 0; i < 21; i++) {
sum = sum + sign * power(x, 2 * i + 1) / fact(2 * i +1);
sign = -sign;
}
return sum;
}
//FUNCTION TO FIND COS(X) USING TAYLOR’S SERIE
double coseFun(double x)
{
double value = 1.0;
for (int i = 2, j = 1;i < 21;i += 2, j++ )
{
value += ( double ) power( -1.0, j ) * power( x, i ) / fact( i ); //taylor series expansion for cosine
series
}
return value;
}
//FUNCTION TO FIND EXP(X) USING TAYLOR’S SERIES
double expoFun(double x)
{
int i = 1;
float ex = 1;
while ( i < 21 )
{
ex += ( float ) power( x, i ) / fact( i ); //taylor series expansion for exponential
++i;
}
return ex;
}
int main() {
double x;
char more;
do {
printf(" tttInput X: ");
scanf("%lf", &x);
printf(" tttt LibraryResult t MyResult");
printf(" tt sin( %.1lf)t %lft%lf", x, sin(x), sineFun(x));
printf(" tt cos( %.1lf)t %lft%lf", x, cos(x), coseFun(x));
printf(" tt exp( %.1lf)t %lft%lf", x, exp(x), expoFun(x));
printf("  ttttDo more (Y/N)?:");
scanf(" %s", &more);
}while(more=='y'||more=='Y');
}
--------------------------------------
OUTPUT:
Input X:
2.4
LibraryResult MyResult
sin(
2.4) 0.675463 0.675463
cos( 2.4) -0.737394 -
0.737394
exp(
2.4) 11.023176 11.023178
Do more
(Y/N)?:Y
Input X: -
2.4
LibraryResult MyResult
sin( -2.4) -0.675463 -
0.675463
cos( -2.4) -0.737394 -
0.737394
exp( -
2.4) 0.090718 0.090718
Do more
(Y/N)?:Y
Input X:
4.4
LibraryResult MyResult
sin( 4.4) -0.951602 -
0.951602
cos( 4.4) -0.307333 -
0.307333
exp(
4.4) 81.450869 81.450882
Do more
(Y/N)?:Y
Input X: -
4.4
LibraryResult MyResult
sin( -
4.4) 0.951602 0.951602
cos( -4.4) -0.307333 -
0.307333
exp( -
4.4) 0.012277 0.012279
Do more (Y/N)?:N

More Related Content

PDF
I wrote the following change it to having a header, main and cpp fi.pdf
PDF
C++ TUTORIAL 9
PDF
You can use the below function for linear interpolation i.e.#inclu.pdf
PDF
public class TrequeT extends AbstractListT { .pdf
PDF
Property-based testing
PDF
Points.java import java.util.ArrayList; import java.util.Scan.pdf
PDF
import java.util.Scanner;public class HornersPolynomial {   .pdf
PPTX
Pragmatic metaprogramming
I wrote the following change it to having a header, main and cpp fi.pdf
C++ TUTORIAL 9
You can use the below function for linear interpolation i.e.#inclu.pdf
public class TrequeT extends AbstractListT { .pdf
Property-based testing
Points.java import java.util.ArrayList; import java.util.Scan.pdf
import java.util.Scanner;public class HornersPolynomial {   .pdf
Pragmatic metaprogramming

Similar to #includestdio.h #includestring.h #includemath.h #include.pdf (20)

PDF
PPT
Arrays and structures
PPTX
ES6(ES2015) is beautiful
DOCX
Interpolation graph c++
PDF
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
PPTX
C++ Lambda and concurrency
PDF
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
DOCX
Computer Graphics Lab File C Programs
PDF
Given the following codepackage data1;import java.util.;p.pdf
PPT
Recursion
PDF
Please read the comment ins codeExpressionTree.java-------------.pdf
PDF
Laziness, trampolines, monoids and other functional amenities: this is not yo...
PDF
Introduction to Computer Graphics using OpenGLCan someone tell me .pdf
PPTX
Scala - where objects and functions meet
PPTX
Chapter 7 functions (c)
DOCX
Write a program that displays an AVL tree along with its balance fac.docx
PDF
062636636366363773737373733+73737733+7.pdf
PPT
SDC - Einführung in Scala
PPTX
Monadic Comprehensions and Functional Composition with Query Expressions
PPTX
EcmaScript unchained
Arrays and structures
ES6(ES2015) is beautiful
Interpolation graph c++
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
C++ Lambda and concurrency
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
Computer Graphics Lab File C Programs
Given the following codepackage data1;import java.util.;p.pdf
Recursion
Please read the comment ins codeExpressionTree.java-------------.pdf
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Introduction to Computer Graphics using OpenGLCan someone tell me .pdf
Scala - where objects and functions meet
Chapter 7 functions (c)
Write a program that displays an AVL tree along with its balance fac.docx
062636636366363773737373733+73737733+7.pdf
SDC - Einführung in Scala
Monadic Comprehensions and Functional Composition with Query Expressions
EcmaScript unchained

More from RITU1ARORA (20)

PDF
Cardiac muscle, connective tissue, an endothelial cells all collectin.pdf
PDF
DOL Co. had the following account balances as of December 1, 2015.pdf
PDF
Describe and contrast allopatric speciation and sympatric speciation..pdf
PDF
compute the present value for 14 years, interest rate 8 future valu.pdf
PDF
Write down the complex potential for a source of strength m locat.pdf
PDF
Write a stack class that has an STL vector as a data member. Your cl.pdf
PDF
Which of the following is NOT a segment asset of an operating segment.pdf
PDF
Why is knowledge of the heritability of a trait important for the st.pdf
PDF
Compare and contrast the physical characteristic of protozoans, yeas.pdf
PDF
Which statement correctly saves the number of items in the variable .pdf
PDF
What does the fossil record of Basilosaurid whales tell us about wha.pdf
PDF
Three decision makers have assessed utilities for the following deci.pdf
PDF
Think about our economy. Irrespective of economic conditions, we con.pdf
PDF
The hardenability curves of several iron alloys are shown in the fig.pdf
PDF
The de Broglie relationships are both valid for bloch electrons. Tur.pdf
PDF
TextBook Error Control Code (Lin and Costello) If the syndrome is z.pdf
PDF
Based on taxonomical classification, to which of the following organi.pdf
PDF
Answer choices are Internalized Principle, Societal Expectations, S.pdf
PDF
An environment would be considered harsh to an organism if it would.pdf
PDF
A committee of three people is to be randomly selected from a group .pdf
Cardiac muscle, connective tissue, an endothelial cells all collectin.pdf
DOL Co. had the following account balances as of December 1, 2015.pdf
Describe and contrast allopatric speciation and sympatric speciation..pdf
compute the present value for 14 years, interest rate 8 future valu.pdf
Write down the complex potential for a source of strength m locat.pdf
Write a stack class that has an STL vector as a data member. Your cl.pdf
Which of the following is NOT a segment asset of an operating segment.pdf
Why is knowledge of the heritability of a trait important for the st.pdf
Compare and contrast the physical characteristic of protozoans, yeas.pdf
Which statement correctly saves the number of items in the variable .pdf
What does the fossil record of Basilosaurid whales tell us about wha.pdf
Three decision makers have assessed utilities for the following deci.pdf
Think about our economy. Irrespective of economic conditions, we con.pdf
The hardenability curves of several iron alloys are shown in the fig.pdf
The de Broglie relationships are both valid for bloch electrons. Tur.pdf
TextBook Error Control Code (Lin and Costello) If the syndrome is z.pdf
Based on taxonomical classification, to which of the following organi.pdf
Answer choices are Internalized Principle, Societal Expectations, S.pdf
An environment would be considered harsh to an organism if it would.pdf
A committee of three people is to be randomly selected from a group .pdf

Recently uploaded (20)

PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Computing-Curriculum for Schools in Ghana
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Updated Idioms and Phrasal Verbs in English subject
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Computing-Curriculum for Schools in Ghana
A systematic review of self-coping strategies used by university students to ...
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Paper A Mock Exam 9_ Attempt review.pdf.
Updated Idioms and Phrasal Verbs in English subject
History, Philosophy and sociology of education (1).pptx
01-Introduction-to-Information-Management.pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
Classroom Observation Tools for Teachers
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE

#includestdio.h #includestring.h #includemath.h #include.pdf

  • 1. #include #include #include #include //FIND FACTORIAL double fact(int n) { int i; double prod = 1.; for(i = 1; i <= n; i++) prod = prod * i; return prod; } //FIND x TO THE POWER OF n double pow(double x, int n) { int i; double prod = 1.; for (i = 0; i < n; i++) prod = prod * x; return prod; } //CALCULATE SIN(x) double sineFun(double x) { double sum = 0.; int i, sign = 1; for (i = 0; i < 21; i++) { sum = sum + sign * pow(x, 2 * i + 1) / fact(2 * i +1); sign = -sign; } return sum; } //FUNCTION TO FIND COS(X) USING TAYLOR’S SERIE double coseFun(double x)
  • 2. { } //FUNCTION TO FIND EXP(X) USING TAYLOR’S SERIES double expoFun(double x) { } int main() { double x; char more; do { printf(" tttInput X: "); scanf("%lf", &x); printf(" tttt LibraryResult t MyResult"); printf(" tt sin( %.1lf)t %lft%lf", x, sin(x), sineFun(x)); printf(" tt cos( %.1lf)t %lft%lf", x, cos(x), coseFun(x)); printf(" tt exp( %.1lf)t %lft%lf", x, exp(x), expoFun(x)); printf(" ttttDo more (Y/N)?:"); scanf(" %s", &more); }while(more=='y'||more=='Y'); } Turbo C-tc Input : 2.4 sin cos( 2.40) exp 2.4 LibraryResult 0.675463 -6.737394 11.823176 MyResult 0.675463 0.737394 11.823176 Do nore Y/N? y Input x: -2.4 MyResult -0.675463 - 0.737394 0.090218 LibraryResult sin? y Input x: 4.4 LibraryRe sult MyResult sin? y Input : 4.4 sin Solution Please find the required methods along with its output. Please see the comments against each line to understand the step. NOTE: while compiling please use the option -lm to avoid undefined reference error.
  • 3. command : gcc -o main *.c -lm #include #include #include #include #define PI 3.1415 //FIND FACTORIAL double fact(int n) { int i; double prod = 1.; for(i = 1; i <= n; i++) prod = prod * i; return prod; } //FIND x TO THE POWER OF n double power(double x, int n) { int i; double prod = 1.; for (i = 0; i < n; i++) prod = prod * x; return prod; } //CALCULATE SIN(x) double sineFun(double x) { double sum = 0.; int i, sign = 1; for (i = 0; i < 21; i++) { sum = sum + sign * power(x, 2 * i + 1) / fact(2 * i +1); sign = -sign; } return sum; } //FUNCTION TO FIND COS(X) USING TAYLOR’S SERIE
  • 4. double coseFun(double x) { double value = 1.0; for (int i = 2, j = 1;i < 21;i += 2, j++ ) { value += ( double ) power( -1.0, j ) * power( x, i ) / fact( i ); //taylor series expansion for cosine series } return value; } //FUNCTION TO FIND EXP(X) USING TAYLOR’S SERIES double expoFun(double x) { int i = 1; float ex = 1; while ( i < 21 ) { ex += ( float ) power( x, i ) / fact( i ); //taylor series expansion for exponential ++i; } return ex; } int main() { double x; char more; do { printf(" tttInput X: "); scanf("%lf", &x); printf(" tttt LibraryResult t MyResult"); printf(" tt sin( %.1lf)t %lft%lf", x, sin(x), sineFun(x)); printf(" tt cos( %.1lf)t %lft%lf", x, cos(x), coseFun(x)); printf(" tt exp( %.1lf)t %lft%lf", x, exp(x), expoFun(x));
  • 5. printf(" ttttDo more (Y/N)?:"); scanf(" %s", &more); }while(more=='y'||more=='Y'); } -------------------------------------- OUTPUT: Input X: 2.4 LibraryResult MyResult sin( 2.4) 0.675463 0.675463 cos( 2.4) -0.737394 - 0.737394 exp( 2.4) 11.023176 11.023178 Do more (Y/N)?:Y Input X: - 2.4 LibraryResult MyResult sin( -2.4) -0.675463 - 0.675463
  • 6. cos( -2.4) -0.737394 - 0.737394 exp( - 2.4) 0.090718 0.090718 Do more (Y/N)?:Y Input X: 4.4 LibraryResult MyResult sin( 4.4) -0.951602 - 0.951602 cos( 4.4) -0.307333 - 0.307333 exp( 4.4) 81.450869 81.450882 Do more (Y/N)?:Y Input X: - 4.4 LibraryResult MyResult
  • 7. sin( - 4.4) 0.951602 0.951602 cos( -4.4) -0.307333 - 0.307333 exp( - 4.4) 0.012277 0.012279 Do more (Y/N)?:N