Showing 1 to 100 with line break at each 10

Display number 1 to 100
There should be linke break after 10, 20, 30 .... etc

We will use math fmod() or % to check the reminder of division by 10
#include <stdio.h>
int main(void){
int i;
for(i=1;i<=100;i++){

    printf("%d,",i);
	if((i%10)==0){
      printf("\n");
	}
}
return 0;
}
More on for loop.

Example: Printing Even Numbers

#include <stdio.h>

int main() {
    for (int i = 2; i <= 10; i += 2) {
        printf("%d ", i);
    }
    return 0;
}

Example: Displaying Numbers with Leading Zeros

#include <stdio.h>

int main() {
    for (int i = 1; i <= 10; i++) {
        printf("%03d\n", i);  // Display numbers with leading zeros (e.g., 001, 002)
    }
    return 0;
}

Example: Printing Odd Numbers

#include <stdio.h>

int main() {
    for (int i = 1; i <= 10; i += 2) {
        printf("%d ", i);
    }
    return 0;
}

Example: Printing Numbers in Reverse Order

#include <stdio.h>

int main() {
    for (int i = 10; i >= 1; i--) {
        printf("%d ", i);
    }
    return 0;
}

Example: Displaying Negative Numbers

#include <stdio.h>

int main() {
    for (int i = -1; i >= -10; i--) {
        printf("%d ", i);
    }
    return 0;
}



plus2net.com






We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer