当前位置:网站首页>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
边栏推荐
- FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法
- With the development of industrial Internet as the starting point, the industry can enter a new stage of development
- Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering
- 见丰知夏|国漫鼻祖丰子恺,数字藏品独家发售
- LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
- oracle设置密码复杂度及设置超时退出的功能
- Encounter with avita 11: long lost freshness under strong product power
- 自媒体行业内卷严重:企业自媒体应该何去何从
- 他原来是这么刷题的!
- Considerations on the construction of operation and maintenance system - stability
猜你喜欢
![[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached](/img/cb/d385bee7a229e8d11f5fa8af66311f.gif)
[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached

【Word 教程系列第 1 篇】如何去除 Word 表格中的箭头
oracle设置密码复杂度及设置超时退出的功能

Realization of 2D code generation in micro build low code

Wave picking of WMS warehouse management system module

How powerful is the Zadig build? Practice together

穿越过后,她说多元宇宙真的存在

Steady! How thousands of micro services can quickly access Zadig (helm chart)

What does project management really manage?

台式机没声音怎么样才能解决
随机推荐
SqlServer复习
Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering
flowable 边界定时器
Oracle删除归档日志及添加定时任务
keil工程,程序写多后,RTT不能打印
Huawei cloud gaussdb (for redis) unveiling issue 19: inventory of six second level capabilities
How to use the apipost script - global variables
Qt5.15中qsrand,srand随机数生成函数已弃用问题
【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码
带链接跳转的微信红包封面制作教程和使用指南
Jointly explore digital technology and information security, and the fourth China Russia Digital Forum was successfully held
Can we still enter the "pit" data analysis now? Look at the hot jobs of data analysis in 2022!
浅析搭建校园在线教学视频汇聚平台的必要性及解决方案
非科班!自学之路!
DBNN实验进展
Career consultation | in the data analysis interview, it is only reliable to introduce yourself in this way
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
自媒体行业内卷严重:企业自媒体应该何去何从
在线文本过滤小于指定长度工具
Explanation: Luogu p1762 even number /6.21 internal examination T2