The cosine of an angle can be computed from the following infinite series: cosx?
ID: 3673079 • Letter: T
Question
The cosine of an angle can be computed from the following infinite series:
cosx?1?x2 ?x4 ?x6 ?........ 2! 4! 6!
Write a program that reads an angle x (in radians) from the keyboard. Then, in a function compute the cosine of the angle using first five terms of the series. Print the value computed along with the value of the cosine computed using the C++ library function.
3. The cosine of an angle can be computed from the following infinite series: cos x = 1--+ +. Q'.. Write a program that reads an angle x (in radians) from the keyboard. Then, in a function compute the cosine of the angle using first five terms of the series. Print the value computed along with the value of the cosine computed using the C++ library function.Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int n, c, k, space = 1;
cout<<"This is program for outputting a diamond formation ";
cout<<"First you must select an odd number diamond width ";
cout<<"Then you must select a lateral offset even or odd ";
cout<<" Enter number of rows: ";
cin>>n;
if(n%2==0)
{
cout<<"ERROR: You entered and even number"<<endl;
cout<<"The program is correcting your error"<<endl;
n=n+1;
}
cout<<"Input lateral offset :";
cin>>space;
for (k = 1; k<=n; k++)
{
for (c = 1; c<space; c++)
cout<<" ";
space--;
for (c = 1; c<= 2*k-1; c++)
cout<<"*";
cout<<" ";
}
space = 1;
for (k = 1; k<= n - 1; k++)
{
for (c = 1; c<= space; c++)
cout<<" ";
space++;
for (c = 1 ; c<= 2*(n-k)-1; c++)
cout<<"*";
cout<<" ";
}
cout<<"Author :"<<"Noelle Belhumeur"<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.