41223108 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • 倉儲維護
    • s.cycu.org維護
    • windows維護
  • weekly progress
    • w1~4
    • w5
    • w6
    • w7
    • w9
    • w12
      • helloworld
      • GD繪圖程式1
    • W13
    • w15
  • ANSIC
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
  • NOTE
    • ssh
    • puttygen
  • 國旗練習
    • Thai
    • Laos
    • Bangladesh
    • vietnam
    • Italian
    • Russia
    • Belgium
    • Ukraine
    • Korea
  • 課程評分
  • Brython
  • setup
  • C_lib
  • replit
  • MSD
  • Final
8. << Previous Next >> 10.

9.

#include <stdio.h>
int main() {
    int i, j, flag, ip = 0;

    // Print a message indicating the purpose of the program
    printf("The prime numbers between 1 and 199 are:\n");

    // Loop to check prime numbers from 2 to 198
    for (i = 2; i < 199; i++) {
        flag = 1;

        // Loop to check if i is divisible by any number other than 1 and itself
        for (j = 2; j <= i / 2 && flag == 1; j++) {
            if (i % j == 0) {
                flag = 0;
            }
        }

        // If i is prime, print it
        if (flag == 1) {
            printf("%5d ", i);
            ip++;

            // Print a newline character after every 10 prime numbers
            if (ip % 10 == 0) {
                printf("\n");
            }
        }
    }

    printf("\n");

    return 0;
}


8. << Previous Next >> 10.

Copyright © All rights reserved | This template is made with by Colorlib