Napisz program c++, który będzie obliczał przybliżenie pierwiastka kwadratowego zgodnie z algorytmem Herona

Baaaaardzo proszę szybkoooo


Odpowiedź :

#include <iostream>

#include <math.h>

using namespace std;

int counter = 0;    //

double Heron(int x,double l)

{

 counter++;  

 double l_neu=(l+(x/l))/2;  // l is used for the guessed solution.

     if(counter==25){  

        return l_neu;

     }else{

     cout << l_neu<< endl; //Every guessed solution will be displayed in the screen.

        return Heron(x,l_neu);

     }

}

int main(){

 int x;

 double l;

   cout << "Write a number n : ";

   cin >> x;

   cout << "Write the guessed solution l : ";

   cin >> l;

   cout << "The Square root of a number x by the Heron Method is :  " << endl <<  Heron(x,l) << endl;

 

system("pause");

  return 0;

}

Viz Inne Pytanie