c++ - Simple for loop I can't figure out -
i'm kind of new c++ last night thought of something. want print out numbers 1-100 10 numbers per line. i'm aware code below wrong prints 1-100 vertically. if can shed light question, appreciated. reading :)
#include <iostream> using namespace std; int main() { for(int x = 1; x <= 100; x++) { cout << x << endl; } }
so want print 10 numbers, carriage return, , 10 numbers, carriage return, , on, correct?
if so, how like:
for(int x = 1; x <= 100; x++) { cout << x << " "; if ((x%10)==0) cout << endl; }
Comments
Post a Comment