当前位置:网站首页>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
边栏推荐
- hiredis的代码示例
- 【Try to Hack】nmap
- How to analyze the trend chart of London gold market with the moving average
- Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
- Websocket for im instant messaging development: concept, principle and common sense of mistakes
- 国盛证券开户是真的安全可靠吗
- 【Word 教程系列第 1 篇】如何去除 Word 表格中的箭头
- Mathematical knowledge: finding combinatorial number I - finding combinatorial number
- Implementation of go language plug-in platform
- 微搭低代码中实现二维码生成
猜你喜欢

After crossing, she said that the multiverse really exists

在QT进行cin(全网最清晰教程)

【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码

Go language - reflect

How to analyze the trend chart of London gold market with the moving average

Powerful open source API interface visual management platform Yapi

00 后云原生工程师:用 Zadig 为思创科技(广州公交)研发开源节流

Hit the industry directly | the flying propeller launched the industry's first model selection tool

YuMinHong set up two funds funded by his hometown

Wave picking of WMS warehouse management system module
随机推荐
Online sql to htmltable tool
Web API learning notes 1
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
Sample code of using redis to realize the like function
数学知识:求组合数 I—求组合数
Linux Installation mysql5.7 (centos7.6) tutorial
WEB API学习笔记1
手机办理股票开户安全性高吗?
利用Redis实现点赞功能的示例代码
超级工厂里的生意图鉴
Google Earth engine (GEE) -- crop extraction and analysis using sentinel-2 data
台式机没声音怎么样才能解决
【HackTheBox】dancing(SMB)
【HackTheBox】 meow
The love digital smart 2022 summit opens, sharing data strategy and building data-driven organization methodology
如何使用伦敦金画出支撑阻力线
[kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box
Advanced workplace | understand the "entry" of position advantages
非科班!自学之路!
Is it safe and reliable for changtou school to help open a securities account? How to drive