In: Computer Science
Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cubed, square root of r, and cube root of r. Use two decimal places for the roots, and zero decimal places for the squares and cubes, and 2 decimal places for the averages. Use commas in numbers 1000 and above. After the loop, print out the average of the r squared and r cubed. Use columns for your data. Print column headings above your loop.Also print the data to a file.
In C++
#include <iostream>
#include <math.h>
using namespace std;
int main() {
double sumSqrt,sumCubrt;
int count=0;
cout<<"Number\tSqure\tCube\t\tSuqureroot\tCube root\n";
for(int i=100;i<1000;i++){
printf("%d \t %d \t %d \t %.2lf \t \t %.2lf \n",i,i*i,i*i*i,sqrt(i),cbrt(i));
//cout<<i<<"\t\t"<<i*i<<"\t"<<i*i*i<<"\t\t"<<sqrt(i)<<"\t\t\t"<<cbrt(i)<<endl;
sumSqrt+=i*i;
sumCubrt+=i*i*i;
count++;
}
cout<<"Average of squres : "<<sumSqrt/count<<endl;
cout<<"Average of Cubes : "<<sumCubrt/count<<endl;
}