assignment

hai :D
can you help me , make a program that can display a number and its square root.
in decending order,by just using :
#include <iostream>
using namespace std;

example:

100=10
99=9.9498
98=9.8994
97=9.8488
.
.
.
.

1=1
0=0

********************************************************************************
i apologize if something's wrong in the construction of my sentence :D,,,
please help me ,its my assignment

TY
************************************************************
#include <iostream>
using namespace std;
main()
{
system ("color 8b");
double num;

cout<<" ENTER A NUMBER :";
cin>>num;
system ("cls");
int x=num;
while (x>=0){

if (x%2){
cout<<"\n ODD NUM :"<<x;
}
else{
cout<<"\n EVEN NUM :"<<x;
}


// the formula of to get the square root of each number is still missing ..pls help sir
x--;
}

system ("pause");

}
Last edited on
Please note, that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.


Hint: a loop. See http://www.cplusplus.com/doc/tutorial/control/
#include <iostream>
using namespace std;
main()
{
system ("color 8b");
double num;

cout<<" ENTER A NUMBER :";
cin>>num;
system ("cls");
int x=num;
while (x>=0){

if (x%2){
cout<<"\n ODD NUM :"<<x;
}
else{
cout<<"\n EVEN NUM :"<<x;
}


// the formula of to get the square root of each number is still missing ..pls help sir
x--;
}

system ("pause");

}
Why do you need to check parity?

sqrt(x) is defined in <cmath> (#include <cmath>, like how you #include <iostream>).
If you asked a specific question more people might help.
Last edited on
thanks 4 advice sir ..but we should not use <cmath> //
check this out sir....but i dont know if the formula to find the square root is correct ..
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>





#include <iostream>
using namespace std;
main()
{
system ("color 8b");
double num,s,v,g,h,i,m;

cout<<" ENTER A NUMBER :";
cin>>num;
system ("cls");
int x=num;
while (x>=1){

s=(x/2+2)/2;
v=(x/s+s)/2;
g=(x/v+v)/2;
h=(x/g+g)/2;
i=(x/h+h)/2;
m=(x/i+i)/2;


if (x%2){
cout<<"\n ODD NUM :"<<x<<" = "<<m;
}
else{
cout<<"\n EVEN NUM :"<<x<<" = "<<m;
}



x--;
}

system ("pause");

}
Please, use code tags and sane indentation. They make posts more readable. See http://www.cplusplus.com/articles/jEywvCM9/

It does look like you are trying to use Babylonian method for computing square root. Is that so?

Your task:
make a program that can display a number and its square root

Does not say anything about "odd and even".
closed account (48T7M4Gy)
It looks like your program gives reasonably accurate answers. But you can get the program to self-check the answers by squaring them and displaying them alongside the original number or taking the difference which should be zero.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

using namespace std;

main()
{
    double num,s,v,g,h,i,m, square;

    cout<<" ENTER A NUMBER :";
    cin>>num;
    int x=num;
    while (x>=1)
    {
        s=(x/2+2)/2;
        v=(x/s+s)/2;
        g=(x/v+v)/2;
        h=(x/g+g)/2;
        i=(x/h+h)/2;
        m=(x/i+i)/2;

        square = m * m;

        if (x%2)
        {
            cout<<"\n ODD NUM :"<<x<<" = "<<m << "  Squared: " << square;
        }
        else
        {
            cout<<"\n EVEN NUM :"<<x<<" = "<<m << " Squared:" << square;
        }
        x--;
    }
}
thanks for that sir :D


#include <iostream>

using namespace std;

main()
{
system("color 8b");
float num,s,v,g,h,i,m, square;

cout<<" ENTER A NUMBER :";
cin>>num;
int x=num;
while (x>=1)
{
s=(x/2+2)/2;
v=(x/s+s)/2;
g=(x/v+v)/2;
h=(x/g+g)/2;
i=(x/h+h)/2;
m=(x/i+i)/2;

square = m * m;

if (x%2)
{

cout<<"\n ODD NUM :" <<"\t"<<x<<"\t = "<<m<<"\t\tSquared:"<<square;
cout<<"\n_____________________";
}
else
{

cout<<"\n EVEN NUM :"<<"\t"<<x<<"\t = "<<m<<"\t\Squared:"<<square;
cout<<"\n_____________________";
}
x--;
}
system("pause");

}
Last edited on
Topic archived. No new replies allowed.