输入一个数字,判断是不是素数。(函数调用法)

#include<stdio.h>
#include<stdlib.h>//执行系统命令的头文件;
#include<Windows.h>//执行睡眠程序的头文件,可加可不加
int su_shu(int i)
{
	int j = 0;
	for (j = 2; j < i; j++)
	{
		if (i%j == 0)
		{
			return 0;//函数
		}
	}
	return 1;
}
int main()
{
	int i = 0;
	scanf("%d", &i);
	int ret = su_shu(i);//函数调用
	if (ret == 0)
	{
		printf("不是素数\n");
	}
	else
	{
		printf("是素数\n");
	}
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/HuiDiExAg/article/details/89521448