TEST1
TEST1-2
Console.WriteLine("请输入一个正整数");
int n =Convert.ToInt32( Console.ReadLine());
if(n%2==0)
{
for(int i=2;i<=n/2;i++)
if (n % i == 0)
Console.WriteLine(i);
}
if(n%2!=0)
{
for(int i=3;i<=(n-1)/2;i++)
if (n % i == 0)
Console.WriteLine(i);
}
TEST1-3
Console.WriteLine("请输入第一个正整数");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入第二个正整数");
int b = Convert.ToInt32(Console.ReadLine());
int temp = Math.Min(a, b);
int result=0;
for(int i=1;i<=temp;i++)
{
if (a % i == 0 && b % i == 0)
result = Math.Max(result, i);
}
Console.WriteLine("最大公约数为:{0}", result);
TEST1-4
Console.WriteLine("请输入第一个正整数");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入第二个正整数");
int b = Convert.ToInt32(Console.ReadLine());
int temp = Math.Max(a, b);
for(int i=temp;i<=a*b;i++)
{
if(i%a==0&&i%b==0)
{
Console.WriteLine("最小公倍数:{0}", i);
break;
}
}
TEST1-5
bool prime = true;
Console.WriteLine("请输入一个正整数");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 2; i <= n / 2; i++)
{
if (n % i == 0)
{
prime = false;
break;
}
}
if (prime)
Console.WriteLine("该正整数是素数");
else
Console.WriteLine("该正整数不是素数");
TEST1-6
Console.WriteLine("请输入一个正整数");
bool square = false;
int n = Convert.ToInt32(Console.ReadLine());
for(int i=2;i<=n/2;i++)
{
if (i * i == n)
{Console.WriteLine("该正整数是平方数,平方根为:{0}", i);
square=true;
}
}
if (!square)
Console.WriteLine("该正整数不是平方数");
TEST1-7
Console.WriteLine("请输入十五位数的身份证号");
string s_ident = Console.ReadLine();
int i;
char ch = ' ';
for( i=0;i<15;i++)
{
ch = s_ident[i];
if (ch < '0' || ch > '9' || s_ident.Length != 15)
{
Console.WriteLine("身份证号格式不正确");
break;
}
}
if(i==15&&s_ident.Length==15)
{
if (ch % 2 == 0)//ASCII码与数值奇偶相对应
Console.WriteLine("性别为女");
else
Console.WriteLine("性别为男");
}
TEST1-8
Console.WriteLine("请输入十八位身份证号码");
string s_ident = Console.ReadLine();
char ch = ' ';
for(int i=0;i<18;i++)
{
ch = s_ident[i];
if (i < 17 && (ch < '0' || ch > '9' || s_ident.Length != 18))
{ Console.WriteLine("身份证号码格式不正确");
break;
}
if (i == 17 && (i != 'x' || (i < '0' || i > '9' || s_ident.Length != 18)))
{
Console.WriteLine("身份证号码格式不正确");
break;
}
if (i == 16 && ch % 2 == 0)
{
Console.WriteLine("性别为女");
break;
}
if (i == 16 && ch % 2 != 0)
{
Console.WriteLine("性别为男");
break;
}
TEST1-9
Console.WriteLine("请输入一串字符串");
string s_text = Console.ReadLine();
char ch = s_text[0];
for(int i=0;i<s_text.Length;i++)
{
if (s_text[i] > ch)
ch = s_text[i];
}
Console.WriteLine("字符串中ASCII码最大的字符是:{0}", ch);
TEST1-10
Console.WriteLine("请输入一串字符串");
string s_text = Console.ReadLine();
char ch = s_text[0];
for (int i = 0; i < s_text.Length; i++)
{
if (s_text[i] <ch)
ch = s_text[i];
}
Console.WriteLine("字符串中ASCII码最小的字符是:{0}", ch);