Question

In: Computer Science

IN C++: Using a single for loop, output the even numbers between 2 and 1004 (inclusive)...

IN C++: Using a single for loop, output the even numbers between 2 and 1004 (inclusive) that iterates (loops) exactly 502 times. The outputted numbers be aligned in a table with 10 numbers per row. Each column in the table should be 5 characters wide. Do not nest a loop inside of another loop.

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main() {

int count=0;

//itearting the numbers

for(int i=2;i<=1024;i+=2){

//printing with 5 char width

printf("%5d",i);

count++;

//if row has 10 numbers than break to next line

if(count%10==0)

printf("\n");

}

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a program in C++ that prints out the even numbers between 1 and 21 using...
Write a program in C++ that prints out the even numbers between 1 and 21 using WHILE loop. Also, find the sum AND product of these numbers and display the resulting sum and product.
Write a loop that will calculate the sum of all even numbers from 2 to 30...
Write a loop that will calculate the sum of all even numbers from 2 to 30 ( including 30) store the result in the variable called thirtySum. Declare and initialize all variables. Answer using programming in c.
Using only real numbers between 0 and 100, inclusive, show the set of three numbers whose...
Using only real numbers between 0 and 100, inclusive, show the set of three numbers whose product is 64 and whose sum is minimal is give by {4, 4, 4}. (a) When is an absolute minimum or maximum guaranteed? (b) State the steps to find an absolute minimum and maximum. (c) Is the space closed and bounded? Explain. (d) Use Lagrange Multipliers to find the minimum and maximum please label and write neatly.
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending...
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending in 3. • Write a for loop to display a string entered by the user backwards.
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please...
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please count and print how many even numbers you have found.
Use the pigeonhole principle to show that if one picks nine numbers between 2 (inclusive), at...
Use the pigeonhole principle to show that if one picks nine numbers between 2 (inclusive), at least two of the numbers chosen must have a common divisor d ≥ 2
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
USING a LOOP for C++ In this lab the completed program should print the numbers 0...
USING a LOOP for C++ 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....
2.c++ if and loop statement Write a program that will count the number of even number...
2.c++ if and loop statement Write a program that will count the number of even number and odd numbers between two inputted numbers. Display the numbers and compute the sum and average of all the even numbers and the sum and average all the odd numbers. Sample outputs: Enter starting number:3 Enter starting number:4 Enter ending number:10 Enter ending number:10 odd numbers Even number 3 4 5 6 7 8 9 10 number of even numbers=4 number of even numbers=4...
Write a program that prints the count of all prime numbers between A and B (inclusive),...
Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT