当前位置:网站首页>C# 面试题目_20220627记录一下
C# 面试题目_20220627记录一下
2022-06-28 23:01:00 【wch3351028】
第一题:x^2 + y^2 = 2000 ,求x和y的所有正整数
public string t1()
{
int tn;
int k = (int)(Math.Sqrt(2000)) + 1;
int x = 0;
StringBuilder sb = new StringBuilder();
while (x < k)
{
tn = 2000 - x * x;
if (IsSquare(tn))
{
sb.AppendLine($"x = {x}, y = {(int)Math.Sqrt(tn)}\n\r");
}
x++;
}
return sb.ToString();
}
//判断是是否为圆形
bool IsSquare(int tn)
{
double x = Math.Sqrt(tn);
return (x - (int)x == 0);
}第二题,求1000以内的质数,并且按照下图排列

public string t2()
{
StringBuilder sb = new StringBuilder();
bool flag;//声明一个bool值用来判断是否是素数
int currentCount = 0;//当前数量
int rowCount = 0;//应该数量
for (int i = 2; i <= 1000; i++)//循环 1000以内的数
{
//每次循环都把flag的值设置为true,
flag = true;
//开始第二次循环,让 i 依次除与 2 和小于它的数,当i= 2时(j < i 条件不成立),直接跳出循环输出:素数 2
for (int j = 2; j < i; j++)
{
//当 i 可以被 j 整除时跳出该循环,该数不是素数,不做输出
if (i % j == 0)
{
flag = false;
break;
}
}
if (flag)
{
if (i == 2 || currentCount == rowCount)
{
sb.AppendLine($" {GetResult(i)}");
rowCount += 2;
currentCount = 0;
}
else
{
sb.Append($" {GetResult(i)}");
currentCount++;
}
}
}
return sb.ToString();
}
string GetResult(int i)
{
if(i > 0 && i < 9)
{
return "00" + i.ToString();
}
else if( i > 10 & i < 99)
{
return "0" +i.ToString();
}
else
{
return i.ToString();
}
}
第三题检查观察代码,分析输出结果

这一题的重点是搞懂
& 运算符的含义
'0' char字符代表的意思
结果是:A1A3A5
边栏推荐
- Production environment sonarqube installation
- 云计算的迷路者
- Realization of 2D code generation in micro build low code
- WMS仓库管理系统模块之波次拣货
- Post-00 cloud native Engineer: use Zadig to increase revenue and reduce expenditure for the R & D of Sichuang Technology (Guangzhou public transport)
- Is it safe and reliable for changtou school to help open a securities account? How to drive
- Detailed steps for MySQL to recover data through IBD files
- Leetcode detailed explanation of stack type
- Considerations on the construction of operation and maintenance system - stability
- The technology giants set up the meta universe standard forum to open up or build a besieged city?
猜你喜欢

Master the usage of const

Qtcreater5.15.0 source code compilation process record

微搭低代码中实现二维码生成

全面掌握const的用法《一》

直击产业落地 | 飞桨重磅推出业界首个模型选型工具

Wechat red envelope cover making tutorial and use guide with link jump

Lecun predicts AgI: big model and reinforcement learning are both ramps! My world model is the new way

00 後雲原生工程師:用 Zadig 為思創科技(廣州公交)研發開源節流

WEB API学习笔记1

CS5463代码模块解析(包含下载链接)
随机推荐
How to solve the problem of desktop without sound
Is the account opening of Guosheng securities really safe and reliable
Google Earth Engine(GEE)——利用sentinel-2数据进行农作物提取分析
Qsrand, srand random number generating function in qt5.15 has been discarded
QtCreator5.15.0源码编译全过程记录
【Try to Hack】nmap
Wave picking of WMS warehouse management system module
全面掌握const的用法《一》
Ansible production environment usage scenario (7): batch deployment of elk clients
Summary of time series prediction series (code usage)
Jointly explore digital technology and information security, and the fourth China Russia Digital Forum was successfully held
Websocket for im instant messaging development: concept, principle and common sense of mistakes
SqlServer复习
强大的开源API接口可视化管理平台-YApi
Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
Post-00 cloud native Engineer: use Zadig to increase revenue and reduce expenditure for the R & D of Sichuang Technology (Guangzhou public transport)
带链接跳转的微信红包封面制作教程和使用指南
【Word 教程系列第 1 篇】如何去除 Word 表格中的箭头
小样本利器2.文本对抗+半监督 FGSM & VAT & FGM代码实现