2023-03-21
自我提升
0

✋编程题
输⼊⼀个正整数n,输出n层的右三⾓形。
样例输⼊4
样例输出

image.png

c#
int n = Convert.ToInt32(Console.ReadLine()); for(int i = 1; i <= n; i++) { // n-i个空格 i个* for(int j = 0; j < n - i; j++) { Console.Write(" "); } for(int j = 0; j < i; j++) { Console.Write("*"); } Console.WriteLine(); }

✋编程题
输⼊⼀个正整数n,输出n层的等腰三⾓形。
样例输⼊4
样例输出

image.png

c#
int n = Convert.ToInt32(Console.ReadLine()); for(int i = 1; i <= n; i++) { //n-i 2*i-1 for(int j = 0; j < n - i; j++) { Console.Write(" "); } for(int j = 0; j < 2 * i - 1; j++) { Console.Write("*"); } Console.WriteLine(); }

✋编程题
输⼊⼀个正整数n,输出n层的菱形。
样例输⼊4
样例输出

image.png

c#
int n = Convert.ToInt32(Console.ReadLine()); for (int i = 1; i <= n; i++) { //n-i 2*i-1 for (int j = 0; j < n - i; j++) { Console.Write(" "); } for (int j = 0; j < 2 * i - 1; j++) { Console.Write("*"); } Console.WriteLine(); } //n-1总行数 空格=行号数 for(int i = 1; i <= n - 1; i++) { for(int j = 0; j < i; j++) { Console.Write(" "); } //* 个数 //n-1-i+1 = (n-i )*2 -1 int countStar = (n - i) * 2 - 1; for (int j = 0; j < countStar; j++) { Console.Write("*"); } Console.WriteLine(); }

✋编程题 输出9x9乘法表。

image.png

c#
for(int i = 1; i <= 9; i++) { //i 右乘数 左乘数1-i for(int j = 1; j <= i; j++) { Console.Write("{0}x{1}={2} ", j, i, i * j); } Console.WriteLine(); }

✋编程题
⽤100⽂买鸡,其中公鸡,⺟鸡,⼩鸡,都必须要有,公鸡3⽂⼀只,⺟鸡5⽂⼀只,⼩鸡2⽂⼀只,请问公鸡、⺟鸡、⼩鸡要买多少只刚好凑⾜100⽂。
把所有的满⾜条件的情况罗列出来。

c#
// x y z 公鸡1-33 母鸡1-20 小鸡1-50 for(int x = 1; x <= 100 / 3; x++) { for(int y = 1; y < 100 / 5; y++) { for(int z = 1; z < 100 / 2; z++) { //是否花了100文 if((x * 3 + y * 5 + z * 2) == 100) { Console.WriteLine("公鸡{0},母鸡{1},小鸡{2}", x, y, z); } } } }

✋输⼊两个整数num1和num2,输出这两个正整数num1和num2的最⼤公约数。

c#
int num1 = Convert.ToInt32(Console.ReadLine()); int num2 = Convert.ToInt32(Console.ReadLine()); int min = num1; if (num2 < min) { min = num2; } for(int i = min; i > 0; i--) { if(num1%i==0 && num2 % i == 0) { Console.WriteLine("最大公约数" + i); break; } }

✋猜数字 由系统⽣成⼀个随机数(1-100),让玩家猜数字,如果猜的数字⽐随机数⼩,输出猜⼩了,如果猜的数字⽐随机数⼤,输出猜⼤了,猜中的话,输出猜中了,并结束游戏,没有猜中的话,就让玩家⼀直猜。

c#
Random rd = new Random();//随机数的生成Random //Console.WriteLine(rd.Next(1, 10)); //伪随机 int number = rd.Next(1, 101); while (true) { Console.WriteLine("猜猜我的数字是多少:"); int numberUser = Convert.ToInt32(Console.ReadLine()); if (numberUser > number) { Console.WriteLine("你猜大了"); }else if (numberUser < number) { Console.WriteLine("你猜小了"); } else { Console.WriteLine("你猜中了"); break; } }

编程题集合1: https://wenku.baidu.com/view/3b89f4112c3f5727a5e9856a561252d381eb204c.html
编程题集合2: https://www.cnblogs.com/drift-code/p/8821582.html