Use c language to determine the number of less than 100 prime examples of c language

  • 2020-04-02 02:15:24
  • OfStack

Enter a number from the console to determine if it is a prime number.


#include <stdio.h>

//Define the function to determine whether it is a prime number
int isPrime(int num ){
    int i;
    //We start at 2, and we go all the way to I squared is less than or equal to the given number.
    for (i = 2; i*i <= num; i++) {
        if ( ( num % i ) == 0 ) {
            return 0;
        }
    }
}

int main(int argc, const char *argv[])
{
    int re;
    int input;
    printf(" Please enter a 100 Integer within :");
    scanf("%d",&input);
    if( input > 1 ){
        re = isPrime(input);
        if(re == 0){
            printf("%d Is not a prime number n",input);
        }else{
            printf("%d It's a prime number n",input);
        }
    }else{
        if(input == 1){
            printf("1 It is neither prime nor composite. n");
        }else{
            printf(" Please enter greater than or equal to 1 The positive integer ^.^n");
        }
    }
    return 0;
}


Related articles: