题目
1.编写一个程序,对输入的4个整数,求出其中的最大值和最小值,并显示出来。
2.让用户输入两个整数,然后再输入0-3之间的一个数,0代表加法,1代表减法,2代表乘法,3代表除法,计算这两个数字的结果
3.求出1~1000之间的所有能被7整除的数,并计算和输出每5个的和。
4.编写一个控制台程序,分别输出1~100之间的平方、平方根。
5.兔子繁殖问题。设有一对新生的兔子,从第三个月开始他们每个月都生一对兔子,新生的兔子从第三个月开始又每个月生一对兔子。按此规律,并假定兔子没有死亡,20个月后共有多少个兔子?要求编写为控制台程序。
6.编程输出1~100中能被3整除但不能被5整除的数,并统计有多少个这样的数。
7.编程输出1000以内的所有素数
8.编程输出九九乘法表。
9.编写一个掷筛子100次的程序,并打印出各种点数的出现次数。
10.一个控制台应用程序,输出1~5的平方值,要求:用for语句实现。用while语句实现。用do-while语句实现。
11.一个控制台应用程序,要求用户输入5个大写字母,如果用户输入的信息不满足要求,提示帮助信息并要求重新输入。
12.一个控制台应用程序,要求完成写列功能。
1)接收一个整数n。
2)如果接收的值n为正数,输出1~n间的全部整数。
3)如果接收的值n为负值,用break或者return退出程序。
4)如何n为0的话 转到1继续接收下一个整数。
13.一个控制台应用程序,求1000之内的所有“完数”。所谓“完数”是指一个数恰好等于它的所有因子之和。例如6是完数,因为6=1+2+3。
代码
using System;
class lianxi
{
public static void Main()
{
Console.WriteLine("Please enter four ints:");
int num1 = Convert.ToInt32(Console.ReadLine());
int num2 = Convert.ToInt32(Console.ReadLine());
int num3 = Convert.ToInt32(Console.ReadLine());
int num4 = Convert.ToInt32(Console.ReadLine());
int m, n, max, min;
m = num1 > num2 ? num1 : num2;
n = num3 > num4 ? num3 : num4;
max = n > m ? n : m;
m = num1 < num2 ? num1 : num2;
n = num3 < num4 ? num3 : num4;
min = n < m ? n : m;
Console.WriteLine("The biggest number is {0}\nThe least number is {1}",max,min);
}
}
using System;
class lianxi2
{
public static void Main()
{
Console.WriteLine("Please enter two numbers.");
int num1 = Convert.ToInt32(Console.ReadLine());
int num2 = Convert.ToInt32(Console.ReadLine());
Random rnd = new Random();
int fin = 0;
int m = rnd.Next(0, 4);
switch (m)
{
case 0:
fin = num1 + num2;
break;
case 1:
fin = num1 - num2;
break;
case 2:
fin = num1 * num2;
break;
case 3:
fin = num1 / num2;
break;
default:
Console.WriteLine("PROGRAM ERROE!!");
break;
}
Console.WriteLine("The seed is {0}", m);
Console.WriteLine("The result is {0}", fin);
Console.ReadKey();
}
}
using System;
class lianxi3
{
public static void Main()
{
int sum = 0;
int num = 1;
for (num = 1; num <= 1000; num++)
{
if (num % 7 == 0)
{
Console.WriteLine(num);
sum += num;
}
else
{
continue;
}
}
}
}
using System;
class lianxi4
{
public static void Main()
{
int num = 1;
int square;
double SquareRoot;
for (num = 1; num <= 100; num++)
{
square = num * num;
SquareRoot = Math.Sqrt(num);
Console.WriteLine("{0}的平方是{1}", num, square);
Console.WriteLine("{0}的平方根是{1}", num, SquareRoot);
}
}
}
using System;
class lianxi5
{
public static void Main()
{
int month = 0, rabbit = 1;
for (month = 1; month <= 20; month++)
{
if (month <= 3 & month > 0)
{
rabbit = 1;
}
if (month <= 5 & month > 3)
{
rabbit += 1;
}
if (month > 5 & month <= 20)
{
rabbit += (month - 4);
}
}
Console.WriteLine("Finally,the rabbits are {0}", rabbit);
}
}
using System;
class lianxi6
{
public static void Main()
{
int num = 1, sum = 0;
for (num = 1; num <= 100; num++)
{
if (num % 3 == 0 & num % 5 != 0)
{
Console.WriteLine(num);
sum += 1;
}
else
{
continue;
}
}
Console.WriteLine("There are {0} such integers", sum);
}
}
using System;
class lianxi7
{
public static void Main()
{
int num, factor;
Console.WriteLine("2");
for (num = 3; num <= 1000; num++)
{
for (factor = 2; factor <= (num - 1); factor++)
{
if (num % factor == 0)
{
break;
}
}
Console.WriteLine(num);
}
}
}
using System;
class lianxi8
{
public static void Main()
{
int line;
Console.WriteLine("0 1 2 3 4 5 6 7 8 9");
for (line = 1; line <= 9; line++)
{
int c1, c2, c3, c4, c5, c6, c7, c8, c9;
c1 = line * 1;
c2 = line * 2;
c3 = line * 3;
c4 = line * 4;
c5 = line * 5;
c6 = line * 6;
c7 = line * 7;
c8 = line * 8;
c9 = line * 9;
Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}", line, c1, c2, c3, c4, c5, c6, c7, c8, c9);
}
}
}
using System;
class lianxi9
{
public static void Main()
{
int num, seed, res1 = 0, res2 = 0, res3 = 0, res4 = 0, res5 = 0, res6 = 0;
Random rnd = new Random();
for (num = 1; num <= 100; num++)
{
seed = rnd.Next(1, 7);
switch (seed)
{
case 1:
res1 += 1;
break;
case 2:
res2 += 1;
break;
case 3:
res3 += 1;
break;
case 4:
res4 += 1;
break;
case 5:
res5 += 1;
break;
case 6:
res6 += 1;
break;
}
}
Console.WriteLine("1 has {0}", res1);
Console.WriteLine("2 has {0}", res2);
Console.WriteLine("3 has {0}", res3);
Console.WriteLine("4 has {0}", res4);
Console.WriteLine("5 has {0}", res5);
Console.WriteLine("6 has {0}", res6);
}
}
using System;
class lianxi10
{
public static void Main()
{
int num, sqr = 0;
Console.WriteLine("Use for");
for (num = 1; num <= 5; num++)
{
sqr = num * num;
Console.WriteLine("{0}^2={1}", num, sqr);
}
Console.WriteLine("-----------------------------");
Console.WriteLine("Use while");
num = 1;
while (num <= 5)
{
sqr = num * num;
Console.WriteLine("{0}^2={1}", num, sqr);
num++;
}
Console.WriteLine("-----------------------------");
Console.WriteLine("Use do...while ");
num = 1;
do
{
sqr = num * num;
Console.WriteLine("{0}^2={1}", num, sqr);
num++;
} while (num <= 5);
}
}
using System;
class lianxi11
{
public static void Main(string[] args)
{
while (true)
{
Console.WriteLine("Please enter five capitals");
string str = Console.ReadLine();
bool judge = true;
for (int i = 0; i < 5; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
}
else
{
judge = false;
break;
}
if (judge == false)
{
Console.WriteLine("Please re-enter!");
}
else
{
break;
}
}
}
}
}
using System;
class lianxi12
{
public static void Main()
{
mabal:
int n = Convert.ToInt32(Console.ReadLine());
int m = 1;
if (n > 0)
{
for (m = 1; m <= n; m++)
{
Console.WriteLine(m);
}
}
else if (n < 0)
{
return;
}
else
{
goto mabal;
}
Console.ReadKey();
}
}
using System;
class lianxi13
{
public static void Main()
{
int num, seed, sum;
for (num = 1; num <= 1000; num++)
{
sum = 0;
for (seed = 1; seed <= (num - 1); seed++)
{
if (num % seed == 0)
{
sum += seed;
}
}
if (sum == num)
{
Console.WriteLine(sum);
}
}
}
}
625



被折叠的 条评论
为什么被折叠?



