Posts

Showing posts from February, 2021

Chapter - 4

Image
click here to Downlod book  Page - 79 Exercise - 4 Solution: #include<iostream> using namespace std; int factorial(int n){ if(n==0){ return 1; } return n * factorial(n-1); } int main(){ float r; cout<<"Enter value of 'r' "<<endl; cin>>r; float ans =0; for(int i=1;i<=r;i++){ if((i&1)==0){ ans+=factorial(r)/factorial(i) ; }else{ ans-=factorial(r)/factorial(i); } } cout<<ans; } Solution: #include<iostream> #include<cmath> using namespace std; float rot(int n){ if(n==0){ return 0; } return sqrt(2+rot(n-1)); } int main(){ int n; cout<<"Enter number of iteration of n"<<endl; cin>>n; float ans =1; for(int i=1;i<=n;i++){ ans*=rot(i)/2 ; } cout<<"from RHS 'solving eqaution' we get : "<<ans<<endl...

Chapter - 1

Download Book page(30) Exercise - 1 In all the problems related to drawing, you are expected to identify the patterns/repetitions in what is asked, and use repeat statements to write a concise program as possible. You should also avoid excessive movement of the turtle and tracing over what has already been drawn. 1. Modify the program given in the text so that it asks for the side length of the polygon to be drawn in addition to asking for the number of sides. solution: #include<simplecpp> main_program{ int length , sides; cout<<"Enter length and number of sides"<<endl; cin>>length>>sides; turtleSim(); repeat(sides){ forward(length); right(360/sides); wait(1); } wait(4); //it is use for pause the turtle for certain time interval } 2. Draw a sequence of 10 squares, one to the left of another. solution: #include<simplecpp> main_program{ turtleSim(...