c#求范围内素数的示例分享(c#求素数)
时间:2022-07-09 22:20:10
程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。
#include <stdio.h>
#include <math.h>
void main()
{
int low,high,t=0;
printf("请输入你想寻找素数的范围(例如10~100,输入10 100)\n");
scanf("%d %d",&low,&high);
if(low>high||low<0)
printf("你所输入的数据有误!");
else
{
for(;low<=high;low++)
{
if(low==1||low==0)
continue;
int j=0;
for(int i=2;i<=sqrt(low);i++)
{
if(low%i==0)
{
j=1;
break;
}
}
if(j==0)
{
if(low<10)
printf("%d ",low);
else
printf("%d ",low);//一位数与两位数的对齐
t++;
if(t%4==0)//没四个为一组,换行操作
printf("\n");
}
}
if(t==0)
printf("您所输入的范围没有素数\n");
printf("\n");
}
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Maven打包时如何指定启动类
![](https://img.aspxhome.com/file/2023/2/67682_0s.png)
Android 各版本兼容性适配详解
![](https://img.aspxhome.com/file/2023/7/96807_0s.jpg)
Java 中的抽象介绍
Java Scanner输入两个数组的方法
SpringCloud如何使用Eureka实现服务之间的传递数据
java使用Feign实现声明式Restful风格调用
C#下listview如何插入图片
Java实现排队论的原理
![](https://img.aspxhome.com/file/2023/2/81992_0s.jpg)
Java中用enum结合testng实现数据驱动的方法示例
![](https://img.aspxhome.com/file/2023/9/65179_0s.png)
Android网络访问之Retrofit使用教程
JavaFx实现拼图游戏
![](https://img.aspxhome.com/file/2023/4/69714_0s.jpg)
解决Android studio 2.3升级到Android studio 3.0 后apt报错问题
整理总结Java多线程程序编写的要点
![](https://img.aspxhome.com/file/2023/5/103975_0s.jpg)
使用Spring自定义实现IOC和依赖注入(注解方式)
![](https://img.aspxhome.com/file/2023/4/58534_0s.png)
C# 特性AttributeUsage简介与使用教程
![](https://img.aspxhome.com/file/2023/1/111141_0s.png)
Spring boot整合log4j2过程解析
![](https://img.aspxhome.com/file/2023/7/60107_0s.png)
基于C#对用户密码使用MD5加密与解密
Android实现拍照及图片裁剪(6.0以上权限处理及7.0以上文件管理)
intellij idea如何将web项目打成war包的实现
![](https://img.aspxhome.com/file/2023/0/75520_0s.png)
详解Android运行时权限及APP适配方法
![](https://img.aspxhome.com/file/2023/1/103881_0s.png)