C# 经典练习题
【摘要】
问题一:求一个数列:1/1,2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
namespace lianxi6._28_1 { class Program { static v...
问题一:求一个数列:1/1,2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
-
namespace lianxi6._28_1
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
int a = 1, b = 1, c;
-
double sum = 0;
-
-
for (int i = 0; i < 20; i++)
-
{
-
sum += 1.0*a / b;
-
c = b;
-
b = a;
-
a = a + c;
-
}
-
-
Console.Write(sum);
-
Console.ReadLine();
-
}
-
}
-
}
问题二:编程找出四位整数abcd 中满足下述关系的数。
//(ab+cd)(ab+cd)=abcd
// 2025 3025
-
namespace lianxi6._28_2
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
for (int a = 1; a <= 9; a++)
-
{
-
for(int b = 0; b <= 9; b++)
-
{
-
for (int c = 1; c <= 9; c++)
-
{
-
for (int d = 0; d <= 9; d++)
-
{
-
int x = a * 10 + b + c * 10 + d;
-
int y = a * 1000 + b * 100 + c * 10 + d;
-
if (x * x == y)
-
{
-
System.Console.WriteLine(y);
-
}
-
}
-
}
-
}
-
}
-
Console.ReadLine();
-
}
-
}
-
}
问题三:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个,以此类推,第10天还是剩了一个。问猴子第一天摘了多少个桃子?
//1534
-
namespace lianxi6._28_3
-
{
-
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
int day = 9, x1 = 0, x2 = 1;
-
for (; day > 0; day--)
-
{
-
x1 = (x2 + 1) * 2;
-
x2 = x1;
-
}
-
Console.Write(x1);
-
Console.ReadLine();
-
}
-
}
-
}
文章来源: czhenya.blog.csdn.net,作者:陈言必行,版权归原作者所有,如需转载,请联系作者。
原文链接:czhenya.blog.csdn.net/article/details/76091915
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)