Skip to content

Latest commit

 

History

History
36 lines (32 loc) · 371 Bytes

33.md

File metadata and controls

36 lines (32 loc) · 371 Bytes

题目:判断一个数字是否为质数(素数)。

#include<stdio.h>
#include <math.h>

int main()
{
	int n;
	scanf("%d", &n);
	int flag = 1;

	if (n <= 0)
	{
		flag = 0;
	}

	for (int i = 2; i < sqrt(n); ++i)
	{
		if (n%i == 0)
		{
			flag = 0;
			break;
		}
	}
	if (flag)
	{
		printf("是素数");
	}
	else
	{
		printf("不是素数");
	}

	return 0;
}