Saturday, January 26, 2013

Write a C++ program calculates the following equation for entered numbers (n, x). 1+1/1+1/1+(sqrt x)..................n terms

Exercise 4)
Write a C++ program and call it series2.cpp which receives two numbers from input (n, x) and calculates the following equation for entered numbers (n, x).
1+1/1+1/1+(sqrt x)..................n terms

Solution-


#include<iostream>
#include<cmath>

using namespace std;


int main()
{
//-------defining variables and initializing them-------------    
    double n,x,i,ans,ans1;
    char redo;
//--------Printing my name on screen----------------    
    cout<<"Welcome to the n term series program  written by Your Name"<<endl;
    cout<<"***************************************************************"<<endl;
    cout<<endl<<endl<<endl;
//--here do loop is used so that the program can be used more then one time
//without exiting the run screen---------------------------    
    do
    {
 //----receiving the variables from input--------------         
    
     cout<<" Please enter two numbers to apply your requested operation"<<endl;
    cout<<"enter the value of n:";
    cin>>n;
    cout<<"enter the value of x:" ;
    cin>>x; 
    cout<<endl;
 // initialising for loop   
    for(i=0;i<=n;i++)
    {
 // the desired expression has the below formulae    
 //when u enter n=0 and x=0 the ans will be 1.5 because our series starts from(1+1/ans1)               
         ans1= (1+1/(1+sqrt(x)));     
         ans=(1+1/ans1);
         }
         //------- printing the results on screen----------- 
         cout<<"the ans of this series="<<ans<<endl;
         //cout<<ans1;        
         
    
          cout<<endl;   
     //----now once again the program will ask the user if want to continue or not          
           cout<<"enter y or Y to continue:";
           cin>>redo;
           cout<<endl<<endl;

           }
           while(redo=='y'||redo=='Y');
           
   system("pause");
    return 0;
    
    }





---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ