1 solutions

  • 0
    @ 2025-11-5 19:24:02

    C :

    #include<stdio.h>
    #include<math.h>
    int prime(int n)
    {
    	for(int i = 2; i * i <= n; i++)
    		if(n % i == 0)
    			return 0;
    		return 1;
    }
    int main()
    {
    	int a;
    	scanf("%d", &a);
    	if(prime(a))
    		puts("prime");
    	else
    		puts("not prime");
    }
    

    C++ :

    #include<iostream>
    using namespace std;
    void judge(int a)
    {
        int b=2;
        while(b<a&&a%b)
            b++;
        if(b==a)
            cout<<"prime"<<endl;
        else cout<<"not prime"<<endl;
    }
    int main()
    {
        int a;
        cin>>a;
        judge(a);
    }
    
    
    • 1

    C语言程序设计教程(第三版)课后习题8.3

    Information

    ID
    19338
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By