current position:Home>Write a function to distinguish prime numbers. Input 20 ~ 100 integers into the main function. It is required to output five prime numbers in each line, and the width of each sequence is four

Write a function to distinguish prime numbers. Input 20 ~ 100 integers into the main function. It is required to output five prime numbers in each line, and the width of each sequence is four

2022-01-27 00:08:58 CSDN Q & A

Write a function to judge prime numbers, and input in the main function 20~100 Integers , It is required to output five prime numbers per line , Each sequence is four wide




Refer to the answer 1:

int prime(int n)
{
if(n<2)
return 0;
for(int i=2;i*i<=n;i++)
if(n%i==0)
return 0;
return 1;
}




Refer to the answer 2:



Refer to the answer 3:
#include <stdio.h>int isprime( int n);int main(){    int sum = 0;    int i;    for( i=1; i<=100; i++ ) {        if(isprime(i)){            printf("%d ", i);            sum+=i;        }    }    printf("\n The sum of prime numbers %d", sum);    return 0;}int isprime(int n){    int i;    if(n<=3) return n>1;    for(i=2;i*i<=n;i++)        if(n%i==0) return 0;    return 1;}



Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270008568506.html

Random recommended