current position:Home>Seek the answer, hoping to program the answer

Seek the answer, hoping to program the answer

2022-01-27 03:58:26 CSDN Q & A

1. Write a custom function , Judge whether a number is prime . The function is called in the main function. , Realization 200 Printing of prime numbers within .
The function is declared as follows :
int sushu(int n);
Function return value : return 1 It means a prime number , return 0 It means that it is not a prime number




Refer to the answer 1:

A simple implementation :

#include <stdio.h>int sushu(int n);int main(void){        int i,j;    // Print 200 The prime number in      for(i=1;i<=200;i++){        j=sushu(i);        if(j==1){            printf("%d ",i);        }     }        return 0;}int sushu(int n){        int i;            // If n Can be 2 To n-1 Divide the number between , It's not a prime number      for(i=2;i<n;i++){         if(n%i==0){            return 0;        }    }        return 1;}



Refer to the answer 2:

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

Random recommended