A normal code:
Code: Select all
#include "iostream.h"
#include "math.h"
#include <stdio.h>
#include <conio.h>
int main()
{
double A,Xold,Xnew;
double d=1;
cout << "Enter the number which square root will be determined";
cin >> A;
Xold=A;
while (d>0.000001;)
{
Xnew=(Xold+(A/Xold))/2;
d=fabs(Xnew-Xold);
Xold=Xnew;
}
cout << "The Square Root of the number is: " << Xnew << "\n";
return 0;
}
Code: Select all
#include "iostream.h"
#include "math.h"
#include <stdio.h>
#include <conio.h>
int main()
{
double A,Xold,Xnew;
double d=1;
char key='y';
do
{
cout << "Enter the number which square root will be determined";
cin >> A;
Xold=A;
while (d>0.000001;)
{
Xnew=(Xold+(A/Xold))/2;
d=fabs(Xnew-Xold);
Xold=Xnew;
}
cout << "The Square Root of the number is: " << Xnew << "\n";
cout << "\nDo you wish to run this program again? Press Y for yes, N for no:";
key=getch();
cout << "\n";
}
while(key=='s'||key=='S');
return 0;
}