MOD% to output new line every 10 characters

1
2
3
4
5
6
7
void printList(int list[],int cnt,int numsPerLine){
    for(int i=0;i<cnt;i++){
        cout<<list[i]<<" ";
        if((i%numsPerLine)==0)
        cout<<"\n";
    }
}


So cnt is 20, numsPerLine is 10, and list[] is initialized with a const = 20

i%numsPerLine on the first loop equals 0 and thus outputs a new line.

I'd like it to new line after 10.

This is novice, I know, but so simple I can't grasp it.

Thanks.
if(i && i%numsPerLine == 0) cout<<"\n";

Don't do it when i is 0
Last edited on
Topic archived. No new replies allowed.