C language implementation, output all prime numbers from 10 to 100

Output all prime numbers between 10 and 100 (prime numbers are not divisible by any other integers except 1 and itself) The
code is implemented as follows:

#include <stdio.h>
#include <math.h>
void main(){
    
    
	int i=11,j,counter=0;
	for(;i<=100;i+=2){
    
     //外层循环为内层循环提供一个奇数
		for(j=2;j<=i-1;j++){
    
     //内存循环判断奇数是否为素数
			if(i%j==0){
    
     //若i不是素数则强行结束内存循环,若i是素数则输出,计数器+1
				break;
			}
		}
		if(j>=i){
    
    
				printf("%6d",i);
				counter++;
				if(counter%10==0){
    
    
					printf("\n"); // 每输出10个素数,则换一行
			}
		}

	}

}


Guess you like

Origin blog.csdn.net/G_whang/article/details/113099591