1.已知变量c = 7,d = 12;判断c是否是能被3整除的数;判断d是否是4的倍数\
namespace TEST
{
class Program
{
static void Main(string[] args)
{
int c = 3, d = 12;
if (c % 3 == 0)
{
Console.WriteLine("c能被3整除");
}
else
{
Console.WriteLine("c不能被3整除");
}
if (d % 4 == 0 && d != 0)
{
Console.WriteLine("d是4的倍数");
}
else
{
Console.WriteLine("d不是4的倍数");
}
}
}
}
2.定义一个变量保存一个分数,判断该分数属于什么等级:60分以下E,60~70D,70~80C,80~90B,90或90以上是A
namespace TEST
{
class Program
{
static void Main(string[] args)
{
int myScore = Convert.ToInt32(Console.ReadLine());
if (myScore >= 90)
{
Console.WriteLine("A");
}
else if (myScore >= 80)
{
Console.WriteLine("B");
}
else if (myScore >= 70)
{
Console.WriteLine("C");
}
else if (myScore >= 60)
{
Console.WriteLine("D");
}
else if (myScore >= 0)
{
Console.WriteLine("E");
}
Console.ReadKey();
}
}
}
3.定义一个变量保存一个不多于五位数的整数,要求:一、求它是几位数,二、逆序打印出各位数字。
namespace TEST
{
class Program
{
static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int a;
int index = 0;
bool flag = true;
int num2 = num;
while (num > 0)
{
num = num / 10;
index++;
}
Console.WriteLine("这个数有{0}位", index);
while (true)
{
int x;
x = num2 % 10;
num2 = num2 / 10;
index--;
Console.Write(x+" ");
if (index == 0)
{
break;
}
}
Console.ReadKey();
}
}
}
4.定义一个变量保存一个整数,然候逆序输出各个数字,并组成一个全新的数字。比如:”123”则输出”321”,如果是”120”则输出”21”
namespace TEST
{
class Program
{
static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int ys = num;
int num1 = num;
int count = 0;
double a = 0;
while (num > 0)
{
num = num / 10;
count++;
}
//Console.WriteLine(count);
while (count >= 1)
{
ys = num1 % 10;
num1 /= 10;
a = ys * Math.Pow(10, count - 1) + a;
count--;
}
Console.WriteLine(a);
Console.ReadKey();
}
}
}
5.输出定义三个变量分别存储双精度数字,进行比较,输出其中最小数。
namespace TEST
{
class Program
{
static void Main(string[] args)
{
double num1 = 1.23, num2 = 2.324, num3 = 3.32, min;
min = num1 < num2 ? num1 : num2;
min = min < num3 ? min : num3;
Console.WriteLine(min);
Console.ReadKey();
}
}
}
6.定义三个变量x,y,z分别保存三个整数,请把这三个数由小到大输出。
namespace TEST
{
class Program
{
static void Main(string[] args)
{
int num1 = 321, num2 = 2, num3 = 43, min, mid = 0, max;
if (num1 < num2)
{
min = num1;
max = num2;
if (min < num3) { }
else { min = num3; }
if (max > num3) { }
else { max = num3; }
}
else
{
min = num2;
max = num1;
if (min < num3) { }
else { min = num3; }
if (max > num3) { }
else { max = num3; }
}
Console.WriteLine(max);
if (min < num1 && num1 < num3)
{
mid = num1;
}
else if (min < num2 && num2 < max)
{
mid = num2;
}
else if (min < num3 && num3 < max)
{
mid = num3;
}
Conso