SlideShare a Scribd company logo
1 of 7
Download to read offline
#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

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

Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogrammingMårten Rånge
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++rpiitcbme
 
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdfANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdfanukoolelectronics
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency명신 김
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfillyasraja7
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfshanki7
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
Introduction to Computer Graphics using OpenGLCan someone tell me .pdf
Introduction to Computer Graphics using OpenGLCan someone tell me .pdfIntroduction to Computer Graphics using OpenGLCan someone tell me .pdf
Introduction to Computer Graphics using OpenGLCan someone tell me .pdffathimafancyjeweller
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
Write a program that displays an AVL tree along with its balance fac.docx
 Write a program that displays an AVL tree  along with its balance fac.docx Write a program that displays an AVL tree  along with its balance fac.docx
Write a program that displays an AVL tree along with its balance fac.docxajoy21
 
Monadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsMonadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsChris Eargle
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 

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

Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogramming
 
662305 10
662305 10662305 10
662305 10
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++
 
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdfANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
 
Recursion
RecursionRecursion
Recursion
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Introduction to Computer Graphics using OpenGLCan someone tell me .pdf
Introduction to Computer Graphics using OpenGLCan someone tell me .pdfIntroduction to Computer Graphics using OpenGLCan someone tell me .pdf
Introduction to Computer Graphics using OpenGLCan someone tell me .pdf
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
Write a program that displays an AVL tree along with its balance fac.docx
 Write a program that displays an AVL tree  along with its balance fac.docx Write a program that displays an AVL tree  along with its balance fac.docx
Write a program that displays an AVL tree along with its balance fac.docx
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Monadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsMonadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query Expressions
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
C++ prgms 3rd unit
C++ prgms 3rd unitC++ prgms 3rd unit
C++ prgms 3rd unit
 

More from RITU1ARORA

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

More from RITU1ARORA (20)

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

Recently uploaded

Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 

Recently uploaded (20)

Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 

#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