Hello,try correcting this code...

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
double n,s,p;
cout<<"input number"<<endl;
cin>>n;

s=sqrt(n);
p=pow(n,2);

while (n>0)
{
cout<<"nombor squareroot powerof2"<<endl;
cout<<" "<<n<<" "<<s<<" "<<p<<endl;
--n;
}
return 0;
}




the problem is the square root and power of 2 is same ..

output.

number squareroot powof2
4 2 16
3 2 16
2 2 16
1 2 16


please inform me on my nazrin_mohdnadzri@yahoo.com

tq
Last edited on
You are computing both the root and the power outside the while loop (ie, only once, and
upon the original value of n).
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
double n,s,p;
cout<<"input number"<<endl;
cin>>n;

s=sqrt(n);
p=pow(n,2);

while (n>0)
{
cout<<"nombor squareroot powerof2"<<endl;
cout<<" "<<n<<" "<<sqrt(n)<<" "<<pow(n,2)<<endl;
--n;
}
return 0;
}

Topic archived. No new replies allowed.