Home > Article > Backend Development > How to output prime numbers between 100 and 200 in C language
Analysis:
First find all the integers within 100~200, and then let these integers find the remainder of numbers other than 1 and itself. If there is any way If it divides evenly, it is not a prime number, otherwise it is a prime number.
Code implementation:
#include<stdio.h> int main() { int conut = 0; int i = 0; for(i=100; i<=200; i++) //先找出来100到200的所有整数,都为i { int j = 0; for(j=2; j<i; j++) //用i去对除了1和它本身以外的数求余 { if(i%j == 0) break; } if(j==i) { conut++; printf("%d ", i); } } printf("\n"); printf("素数个数为:%d\n", conut); return 0; }
Recommended tutorial: c language tutorial
The above is the detailed content of How to output prime numbers between 100 and 200 in C language. For more information, please follow other related articles on the PHP Chinese website!