1170 Problem S "C Programming Language" Jiang Po Kushiro Editor - Exercises 5-4- prime table

Problem Description

Input from the keyboard m, n
in each row on the screen of all primes between 10 m ~ n output format

Entry

Two integers mn

Export

Primes between m ~ n, each row 10, with a space after each number. If m and n are primes contains

Sample input

100 200

Sample Output

101 103 107 109 113 127 131 137 139 149 
151 157 163 167 173 179 181 191 193 197 
199 

AC Code

#include <stdio.h>
#include <math.h>

int find(int num){
    for (int i =2; i<num -1; i++) {
        if (num %i == 0){
            return 0;
        }
    }
    return 1;
}
int main(){
    int m ,n;
    int count =0;
    scanf("%d%d",&m,&n);
    for (int i = m; i<=n; i++) {
        int k = find(i);
        if (k == 1 ) {
            if (count == 10) {
                count =0;
                printf("\n");
            }
            printf("%d ",i);
            count++;
        }
    }
}

Published 119 original articles · won praise 28 · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_41179709/article/details/103964720