当前位置:网站首页>Absolute primes (C language)

Absolute primes (C language)

2022-07-06 21:16:00 Bamboo pride

problem : Write a program , Enter two positive integers , Output absolute primes between two positive integers ;

Operation diagram :

Source code :

#include <stdio.h>
                      
int main()
{
	int a,b;
    int i,x,y,z;
    int h=0,v;
	scanf("%d %d",&a,&b);

	for(i=a;i<=b;i++)
	{
		int j;
		for(j=2;j<i;j++)
		{
			if(i%j==0)
			{
				break;
			}
		}
	if(j==i)
		{
			i=j;
			x=i%10;
			y=(i%100)/10;
			z=i/100;
			if(z==0)
			{
			    h=x*10+y;
			}
			if(z>0)
			{
				h=x*100+y*10+z;
			}
			h=h;
			for(v=2;v<h;v++)
			{
				if(h%v==0)
				{
					break;
				}
			}
			if(v==h)
			{
				printf("%d\n",i);
			}
		}
	}
                             
	return 0;
}

 

原网站

版权声明
本文为[Bamboo pride]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131125513021.html