Simple Squares NOT using loops.

Hey guys I have to make a program to print squares and square roots of all numbers from 1-81 using functions only. Each line I have to print the number, it's square, and its square root.

So far I have this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
double squarerootchart() {    //my function to call upon when i need this table displayed
	double x = 0;
	for (double x = 1; x < 82; x++)
	{
		double y = x;
		double z = sqrt(x);
		double a = pow(x, 2);
		cout << y << std::setw(20) << z << std::setw(20) << a << endl;
	}
	return x;
}
int main() {				//main function that calls upon squarerootchart
	cout << "These are all the square and square roots of numbers 1-81:" << endl;
	cout << " " << endl;
	cout << "Integer" << std::setw(18) << "Square Root" << std::setw(18)<< "Square" << endl;
	squarerootchart();
}


How can I simplify this even further? I am confused on what steps to take next so I don't need the for loop in my squarerootchart function.
using functions only.

Semantically, you could call C++ Standard Library algorithm functions.

However, perhaps recursion is what your teacher expects?
Does goto count as a loop construct?
Ah yes! I do remember my professor saying that we have to use recursion, where would I begin to do so?
Topic archived. No new replies allowed.