当前位置:网站首页>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
边栏推荐
- Panxiaoming, senior vice president of IC nansha|amd and President of Greater China: process, architecture and platform optimization break through the computing boundary
- 【网关开发】ngx嵌套lua时处理CIDR表示的IP地址段
- Huawei cloud gaussdb (for redis) unveiling issue 19: inventory of six second level capabilities
- Progress of dbnn experiment
- Zadig + cave Iast: let safety dissolve in continuous delivery
- go语言插件平台的实现思路
- Go language - reflect
- 稳!上千微服务如何快速接入 Zadig(Helm Chart 篇)
- Encounter with avita 11: long lost freshness under strong product power
- Ingénieur natif du nuage après 00: utiliser Zadig pour développer des sources ouvertes et des économies d'énergie pour la technologie innovante (bus de Guangzhou)
猜你喜欢

如何使用伦敦金画出支撑阻力线

CS5463代码模块解析(包含下载链接)
![[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

DBNN实验进展

k线图基础知识图解——单根K线的含义

深入虚拟内存(Virtual Memory,VM)

台式机没声音怎么样才能解决

Encounter with avita 11: long lost freshness under strong product power

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

直击产业落地 | 飞桨重磅推出业界首个模型选型工具
随机推荐
In the era of industrial Internet, the Internet in the traditional sense will evolve into many new forms
[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word
Master the usage of const
Post-00 cloud native Engineer: use Zadig to increase revenue and reduce expenditure for the R & D of Sichuang Technology (Guangzhou public transport)
Redis+aop+ user defined annotation to realize flow restriction
复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
如何结合均线分析伦敦金行情走势线图
穿越过后,她说多元宇宙真的存在
k线图基础知识图解——单根K线的含义
Career consultation | in the data analysis interview, it is only reliable to introduce yourself in this way
What is the difference between WMS warehouse management system and ERP
LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
邂逅阿维塔 11:强产品力下久违的新鲜感
Jointly explore digital technology and information security, and the fourth China Russia Digital Forum was successfully held
Linux Installation mysql5.7 (centos7.6) tutorial
【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码
[chapter 71 of the flutter problem series] mutual conversion between uint8list and image in flutter
强大的开源API接口可视化管理平台-YApi
Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
Mono's execution process