2.13 END OF CHAPTER PROGRAMS
2.13.1 Sum of series
Problem: Write a program to calculate sin x for given x in degrees by
- Using series expansion
- Using library function sin().
Solution: See Program 2.11.
Program 2.11 sin(x) using series
// sinx.cpp#include<iostream.h>#include<conio.h>#include<math.h>int main(){ int i ; float sum=0,term =1; float x,y; cout << “<---sinx.cpp--->” << endl; cout << “Give X between 0 to 90 degrees : ” ; cin >> y; x = y * 3.14159 /180.0 ; // x in radian sum=term =x; i=1; while (i<15) { i=i+2; term = -1 * term * x * x/i/(i-1); sum= sum + term; } cout <<”The value of sine ” << y << “ Degrees” << endl; cout << “ By the series method : ” << sum <<endl; cout << “By using library function sin : ”<<sin(x)<<endl; ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.