trying to print the square roots of numbers with rows and columns

this is what i have so far


#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;
cout << "Enter positive number of rows" << endl;
cin >> v;
for(int c=1; c<=v; c++){
for(int r=1; r>=v; r--){
cout << sqrt(r);
cout << endl;
}
}
return 0;
}

im trying to get the program to print this as an example if the user enters 5 (the rounding of the decimal is optional).

1 1.41 1.73 2 2.24
1 1.41 1.73 2
1 1.41 1.73
1 1.41
1
i dont understand why its not reading my for loop for rows its only doing columns can anyone please point me in the right direction thanks.
If you enter 5 the second for loops never executes because 5>1.
I think you should remove the second for loop.
i did that and its still not showing me the rows only vertical cloumns
This works :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;
cout << "Enter positive number of rows" << endl;
cin >> v;
for(int i=v; i>=0; i--)
{
    for(int c=1; c<=i; c++)
    {
        cout << sqrt(c);
        cout << "  ";
    }
    cout << endl;
}
int pause;
cin >> pause;
return 0;
}


Edit:
Or if you want it to repeat use this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;
while(true)
{
    cout << "Enter positive number of rows" << endl;
    cin >> v;
    for(int i=v; i>=0; i--)
    {
        for(int c=1; c<=i; c++)
        {
            cout << sqrt(c);
            cout << "  ";
        }
        cout << endl;
    }
}
return 0;
}
Last edited on
yea you are correct i could have sworn i tried this earlier thanks though appreciate your help
Topic archived. No new replies allowed.