Create Program Take Real Number Provided User Divide Four Repeatedly Less 00001 Iteration Q37206919

Create a program that will take a real number provided by theuser and divide it by four repeatedly until it is less than 0.0001.In each iteration, display the iteration number and new value ofthe number.

Using C++.


Answer


Divide.cpp

#include<iostream>
using namespace std;
int main()
{
   // variables declaration
   double number;
   int count=0;
   cout<<“Enter a real number: “;
   cin>>number; // getting a real number fromuser
   // while loop
   while(number>0.0001)
   {
       number/=4;
       count++;
       if(number>0.0001)
       {
          cout<<“Iteration no: “<<count<<endl;
           cout<<“Newvalue of number: “<<number<<endl;
       }
   }
   return 0;
}

Output

CAUsersAKSHAY Desktop Divide.exe Enter a real number: 1e Iteration no: 1 New value of number: 2.5 Iteration no: 2 New value

CAUsersAKSHA Desktop Divide.exe Enter a real number: 58 Iteration no: 1 New value of number 14.5 Iteration no: 2 New value o

CAUsersAKSHAY

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.