for
(
int
i
=
0
; i
<
99
;i
++
)
{
Random rnd = new Random();
// 运算符
int opera = rnd.Next( 1 , 5 );
// opera = 4;
int result = 0 ;
int num1 = 0 ;
int num2 = 0 ;
int input;
do
{
result = rnd.Next( 20 );
} while (result < 1 );
char op = ' \0 ' ;
switch (opera)
{
case 1 : // 加
// Console.WriteLine("{0}",result);
num1 = rnd.Next( 1 ,result);
// Console.WriteLine(num1);
num2 = result - num1;
// Console.WriteLine(num2);
op = ' + ' ;
break ;
case 2 : // 减
num2 = rnd.Next( 1 ,result);
num1 = result + num2;
op = ' - ' ;
// Console.WriteLine("{0}-{1}=?",num1,num2);
break ;
case 3 : // 乘
if (result % 2 != 0 )result ++ ;
num1 = rnd.Next( 1 ,result);
// if(result%num1!=0)num1++;
num2 = result / num1;
// if(result%num1!=0)num2++;
result = (result == (num1 * num2) ? result:(num1 * num2));
op = ' * ' ;
break ;
case 4 : // 除
result = rnd.Next( 1 , 10 );
if (result % 2 != 0 )result ++ ;
num2 = rnd.Next( 1 ,result);
num1 = result * num2;
op = ' / ' ;
break ;
}
Console.WriteLine( " -------\n{0}{2}{1}=?({3}) " ,num1,num2,op,result);
int .TryParse(Console.ReadLine() as string , out input);
Console.WriteLine(input == result);
}
{
Random rnd = new Random();
// 运算符
int opera = rnd.Next( 1 , 5 );
// opera = 4;
int result = 0 ;
int num1 = 0 ;
int num2 = 0 ;
int input;
do
{
result = rnd.Next( 20 );
} while (result < 1 );
char op = ' \0 ' ;
switch (opera)
{
case 1 : // 加
// Console.WriteLine("{0}",result);
num1 = rnd.Next( 1 ,result);
// Console.WriteLine(num1);
num2 = result - num1;
// Console.WriteLine(num2);
op = ' + ' ;
break ;
case 2 : // 减
num2 = rnd.Next( 1 ,result);
num1 = result + num2;
op = ' - ' ;
// Console.WriteLine("{0}-{1}=?",num1,num2);
break ;
case 3 : // 乘
if (result % 2 != 0 )result ++ ;
num1 = rnd.Next( 1 ,result);
// if(result%num1!=0)num1++;
num2 = result / num1;
// if(result%num1!=0)num2++;
result = (result == (num1 * num2) ? result:(num1 * num2));
op = ' * ' ;
break ;
case 4 : // 除
result = rnd.Next( 1 , 10 );
if (result % 2 != 0 )result ++ ;
num2 = rnd.Next( 1 ,result);
num1 = result * num2;
op = ' / ' ;
break ;
}
Console.WriteLine( " -------\n{0}{2}{1}=?({3}) " ,num1,num2,op,result);
int .TryParse(Console.ReadLine() as string , out input);
Console.WriteLine(input == result);
}