我是这样写的,看不出错到哪儿了。
int a=1, b, c,d;
string s, q, l;
s = Console.ReadLine();
a = int.Parse(s);
q = Console.ReadLine();
b = int.Parse(q);
l = Console.ReadLine();
c = int.Parse(l);
d = a;
if (a < b)
{
d = b;
a = b;
}
if (a < c)
d = c;
Console.WriteLine(a);
程序要求是输入三个数,然后比较大小。
请问用这条语句有错么?编写过程没错误提醒啊。
string s, q, l;
s = Console.ReadLine();
a = int.Parse(s);
你的没有错!只是比较原始而已。我给你的代码不公可以判断三组数大小,还可以判断10个,100个,1000个都可以!如果以你的方法判断个100可能都头大了
将判断部分做如下修改:
d = a;因为只是要找到最大的值,所以不用那么麻烦的交换。
而对于你的问题就是,你在a<b的if语句中将a和d都等于b,而最后的判断中仅将d等于c,那么输出a是没有意义的。
追问谢谢,改过了。