Question

In: Computer Science

Print out a table of powers. Use a for loop that goes from 101 to 112...

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++

Solutions

Expert Solution

#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;

}


Related Solutions

Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
When the electricity goes out on your campus, a backup source powers the servers that handle...
When the electricity goes out on your campus, a backup source powers the servers that handle communications and the internet. Rather than use batteries, many installations use a flywheel, a heavy rotating disk that spins, very rapidly with nearly zero friction. An electric motor spins up the flywheel, which continues to spin with very little energy input. When the ststem needs to provide power, the flywheel's motion is used to turn an electric generator. A typical system has a 540...
2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
JAVA Write nested while loop that will print out this pattern, based upon a number entered...
JAVA Write nested while loop that will print out this pattern, based upon a number entered by the user. User enters 4: 1234 1234 1234 1234 User enters 2: 12 12
Set up a for loop to print values from n down to 1 with at most...
Set up a for loop to print values from n down to 1 with at most 5 values per line. For example, when n is 7 then the output is shown below: 7    6    5    4    3 2    1 C++ code
Print greeting Prompt the user for starting odometer reading Use a while loop to validate that...
Print greeting Prompt the user for starting odometer reading Use a while loop to validate that starting odometer reading is a positive number. Initialize variables: last odometer reading, current odometer reading, leg number, total fuel, moreInput While moreInput == ‘y’ Prompt the user for new odometer reading and fuel consumed If fuel is positive and new odometer reading > last odometer reading: Calculate MPG for this leg using mpg = (new odometer – last odometer) / fuel Print MPG for...
You MUST use a while loop to print numbers 1-100. If the number is divisible by 3 print Soda instead of the number.
You MUST use a while loop to print numbers 1-100. If the number is divisible by 3 print Soda instead of the number. If the number is divisible by 5 print Pop instead of the number. If the number is divisible by 3 AND 5 print *SP*.Print 10 numbers/words to a line. Display the numbers/words in right-aligned columns. Use printf statements to do this. For example:System.out.printf( "5d", number );    System.out.printf( "5s", "Soda" );Every time there are ten numbers on a...
powers: Write a program to display the following table with headings and totals. You must use...
powers: Write a program to display the following table with headings and totals. You must use variables to represent all quantities and a for loop for repetition.          x       x^2      x^3          11      121      1331          14      196      2744          17      289      4913          20      400      8000          23      529      12167          26      676      17576          29      841      24389          32      1024     32768          35      1225     42875          38      1444     54872 Totals:  245     6745     201635
IN C++: Write a program to display the following table. MUST use for-loop Enter the table...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table size: 10 N N^2 Square root of N --------------------------------------------- 1 1 1.00 2 4 1.41 3 9 1.73 ….. 10 100 3.16
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345...
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345 1) the source code (.java file), and 2) the screenshot of running results of each question.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT