C语言从键盘输入两个数,求两个数之间素数的个数并打印所有素数(定义法)

#include <stdio.h>
int main()
{
	int a,b;
	printf("please input two numbers \n");
	scanf("%d %d",&a,&b);
	prime(a,b);
	return 0;
}

int prime(int x,int y)
{
	int i,j,k,cout;
	cout=0;
	for(i=x;i<=y;i++)
	{
		k=1;
		for(j=2;j<=i/2;j++)
		{
			if(i%j==0)
			{
				k=0;
				break;
			}
		}
			if(k)
			{
				printf("%d \n",i);
				cout++;
			}
	}
	printf("there are %d numbers from %d to %d \n",cout,x,y);
	return 0;
}

    原文作者:qq_15029743
    原文地址: https://blog.csdn.net/qq_15029743/article/details/79107384
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞