用C语言编写一个检查素数的程序?

参考以下代码实现:

#include<stdio.h>      
#include<conio.h>      
void main()      
{      
    int n,i,m=0,flag=0;    //declaration of variables.  
    clrscr();    //It clears the screen.  
    printf("Enter the number to check prime:");      
    scanf("%d",&n);      
    m=n/2;      
    for(i=2;i<=m;i++)      
    {      
        if(n%i==0)      
        {      
            printf("Number is not prime");      
            flag=1;      
            break;    //break keyword used to terminate from the loop.  
        }      
    }      
    if(flag==0)      
        printf("Number is prime");      
    getch();    //It reads a character from the keyword.  
}

相关文章

在C语言中声明变量:变量声明仅在编译时向编译器提供以给定类...
全局变量和静态全局变量有不同的联系。 这就是全局变量可以在...
存储类决定程序中变量或函数的范围(生命周期)和范围(可见性)...
在C语言中,外部静态变量有内部链接,内部静态变量没有链接。...
让我们先来看一下 typedef 和宏的简短描述,以了解它们之间的...
编译器错误。 解释:typedef 已被视为部分存储类,因此不能一...