Write a short program that declares and initializes double variables one,two, three, four, and five to the values 1.000, 1.414, 1.732, 2.000, and 2.236, respectively. Then write output statements to generate the following legend and table. Use the tab escape sequence \t to line up the columns. If you are unfamiliar with the tab character, you should experiment with it while doing this exercise. A tab works like a mechanical stop on a typewriter.
A tab causes output to begin in a next column, usually a multiple of eight spaces away. Many editors and most word processors will have adjustable tab stops. Our output does not.
The output should be:
N Square Root
1 1.000
2 1.414
3 1.732
4 2.000
5 2.236
Program Code:
#include <iostream>
using namespace std;
int main ()
{
// Declares and initializes double variables one,two, three, four,
// and five to the values 1.000, 1.414, 1.732, 2.000, and 2.236
double one(1.000);
double two(1.414);
double three(1.732);
double four(2.000);
double five(2.236);
//Display output statements to generate the following
//legend and table by using a tab causes '\t' used for
//output to begin in a next column, usually a multiple
//of eight spaces away.
cout << "\tN\tSquare Root\n";
cout << "\t1\t" << one << endl
<<"\t2\t"<<two<<endl
<<"\t3\t"<<three<<endl
<<"\t4\t"<<four<<endl
<<"\t5\t"<<five<<endl;
return 0;
}
Output of the program code:
N Square Root
1 1
2 1.414
3 1.732
4 2.000
5 2.236