In: Computer Science
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.
#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