I NEED THIS IN C++ PLEASE!
In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions: Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and by 10. Execute the program by clicking the Run button at the bottom of the screen. Is the output the same?
The code is as following:
# include <iostream>
using namespace std;
int main() {
//use a loop from 0 through 10
for (int i=0; i<=10; i++) {
//use the loop control variable to output the numbers
cout << "Number: " << i << " 2*Number: " <<
2*i << " 10*Number: " << 10*i << endl;
}
return 0;
}
Here is the output:
Number: 0 2*Number: 0 10*Number: 0
Number: 1 2*Number: 2 10*Number: 10
Number: 2 2*Number: 4 10*Number: 20
Number: 3 2*Number: 6 10*Number: 30
Number: 4 2*Number: 8 10*Number: 40
Number: 5 2*Number: 10 10*Number: 50
Number: 6 2*Number: 12 10*Number: 60
Number: 7 2*Number: 14 10*Number: 70
Number: 8 2*Number: 16 10*Number: 80
Number: 9 2*Number: 18 10*Number: 90
Number: 10 2*Number: 20 10*Number: 100
Comment in case of any doubts.
Get Answers For Free
Most questions answered within 1 hours.