当前位置: 首页 > news >正文

福州网站设计企业培训公司

福州网站设计,企业培训公司,方圆网 网站建设,行业网站域名选择判断质数问题 输⼊⼀个正整数&#xff0c;判断该数是否是质数。如果为质数输出 yes&#xff0c;如果不是输出no 样例输⼊113 输出yes int n Convert.ToInt32(Console.ReadLine()); int count 0; for (int i 1; i < n 1; i) {if (n % i 0) // 判断该数能被整除{coun…

 判断质数问题

输⼊⼀个正整数,判断该数是否是质数。如果为质数输出 yes,如果不是输出no

样例输⼊113 输出yes

int n = Convert.ToInt32(Console.ReadLine());
int count = 0;
for (int i = 1; i < n + 1; i++)
{if (n % i == 0) //  判断该数能被整除{count++; // 计数器+1}
}
if (count == 2) // 次数为2代表1和它本身,即为质数
{Console.WriteLine("yes");
}
else
{Console.WriteLine("no");
}

输出因数问题

输⼊⼀个整数,输出该整数的因数个数和所有因数。
样例输⼊ 9 样例输出 3  1  3  9

int n = Convert.ToInt32(Console.ReadLine());
int count = 0;
string a = ""; // 定义空字符串变量,为了后面存储所有因数
for (int i = 1; i < n + 1; i++)
{if (n % i == 0) // 因数就是能被整除的数{count++;  // 次数+1a += i + " "; // 因数存储}
}
Console.WriteLine(count); // 输出因数个数
Console.Write(a); // 输出所有的因数

整数插入有序数组组成新的有序数组:

有n(n<=100)个整数,已经按照从⼩到⼤顺序排列好,现在另外给⼀个整数x,请将该数插⼊到序列中,并使新的序列仍然有序。输出新的序列。

样例输入:10 20 30 40 50        15   样例输出:10 15 20 30 40 50

class Program{static void Main(string[] args){string str = Console.ReadLine();// 输入有序数组// 将字符数组转换为整数数组string[] strArray = str.Split(' ');int[] intArray = new int[strArray.Length];for (int i = 0; i < strArray.Length; i++){int num = Convert.ToInt32(strArray[i]);intArray[i] = num; // 赋值}// 给的整数xint x = Convert.ToInt32(Console.ReadLine());int nIndex = intArray.Length - 1;// 假设索引是最后一位for (int i = 0; i < intArray.Length - 1; i++){if (x >= intArray[i] && x <= intArray[i + 1]) // 找出该整数的索引{nIndex = i;break;}}if (x < intArray[0]) // 特殊情况,该整数为最小值时{nIndex = -1;}int[] intNewArray = new int[intArray.Length + 1]; // 定义新数组// 0-nIndex = 0 - -1for (int i = 0; i < nIndex + 1; i++){intNewArray[i] = intArray[i]; // 遍历到nIndex + 1给新数组赋值}intNewArray[nIndex + 1] = x; // 将该整数也放入新数组中// nIndex+1 -- length-1for (int i = nIndex + 1; i < intArray.Length; i++){intNewArray[i + 1] = intArray[i];  // 从nIndex + 1开始继续遍历给新数组赋剩余的值}foreach (int num in intNewArray){Console.Write(num + " ");// 输出新的有序数组}}}

http://www.dt0577.cn/news/8826.html

相关文章:

  • 张家口做网站哪家好站长网站查询工具
  • 做网站开发工资怎样典型的口碑营销案例
  • 5网站建设2023搜索最多的关键词
  • 苏州网站网页设计百度推广案例及效果
  • 网站后台数据库下载高清视频线和音频线的接口类型
  • 网站开发建设成本网站建设
  • wordpress可视化编辑页面镇江百度关键词优化
  • 胶州网站制作58同城推广
  • 做零食的网站有哪些百度网页版入口链接
  • 网站怎么做长尾词石家庄seo结算
  • 谷歌网站地图提交百度用户服务中心人工电话
  • 深圳大促网络科技有限公司新网站怎么做优化
  • 重庆网站seo案例口碑营销
  • 中国建设银行官方网址是多少广州各区正在进一步优化以下措施
  • 网络 网站建设百度用户服务中心官网电话
  • 江西建设网官方网站软文代写接单平台
  • 网站建设seo视频友情链接交换形式
  • 国内机械加工企业排名长春seo整站优化
  • 培训机构线上引流推广方法富阳seo关键词优化
  • 北京展览网站建设免费建站平台
  • 青岛好的网站制作推广怎么做电商新手入门
  • 佛山网站建设科技有限公司百度百科官网登录
  • 河南锦路路桥建设有限公司网站中国十大互联网公司排名
  • 做购物网站的业务360搜索首页
  • 深圳定制建站公司电话seo优化课程
  • 如何在word上做网站网址seo排名关键词
  • 网站建设联系方式大数据智能营销系统
  • 深圳做棋牌网站建设多少钱百度关键词优化排名技巧
  • seo网站优化网站编辑招聘搜索指数查询
  • 婚庆设计图网站搜索引擎营销概念