永发信息网

求最大值的小程序 C语言

答案:3  悬赏:80  手机版
解决时间 2021-02-15 17:20
  • 提问者网友:泪痣哥哥
  • 2021-02-15 04:35
#include<stdio.h>
int main()
{
int a,b,c,t;
printf("please input 3 numbers:");
scanf("%d,%d,&d",&a,&b,&c);
if(a>b)
{
{if(a>c)
t=a;
else t=c;}
else
{if(b>c);
t=b;
}
else t=c;
printf("The three numbers are:%d,%d,%d",&a,&b,&c);
printf("The max number is:%d",&t);}
return 0;
}
它说我有4个错误,求指导~
最佳答案
  • 五星知识达人网友:琴狂剑也妄
  • 2021-02-15 06:10
#include<stdio.h>
int main()
{
int a,b,c,t;
printf("please input 3 numbers:");
scanf("%d,%d,&d",&a,&b,&c); //改为scanf("%d,%d,%d",&a,&b,&c);
if(a>b)
{
{if(a>c)
t=a;
else t=c;}
else
{if(b>c);
t=b;
}
else t=c;
printf("The three numbers are:%d,%d,%d",&a,&b,&c); //改为printf("The three numbers are:%d,%d,%d",a,b,c);
printf("The max number is:%d",&t);} //改为printf("The max number is:%d",t);
return 0;
}
循环处改为<思路是对的,但大括号标示有错>:
if(a>b)
{
if(a>c)
t = a;
else
t=c;
}
if(b>c)
t = b;
else
t=c;
全部回答
  • 1楼网友:十年萤火照君眠
  • 2021-02-15 06:45
temp=(((a[0]>a[1])?a[0]:a[1])>a[2]?:((a[0]>a[1])?a[0]:a[1]):a[2]); temp就是最大值 不好意思,上面那个多谢了一个冒号,当时没有验证就直接写了,现在已经验证完毕: 具体代码: #include int main() { int a[3]; a[0]=1; a[2]=3; a[1]=2; int temp=(((a[0]>a[1])?a[0]:a[1])>a[2]?((a[0]>a[1])?a[0]:a[1]):a[2]); printf("%d",temp); return 0; }
  • 2楼网友:纵马山川剑自提
  • 2021-02-15 06:28
#include<stdio.h> int main() { int a,b,c,t; printf("please input 3 numbers:"); scanf("%d,%d,%d",&a,&b,&c); t=a; if(t<b) t=b; if(t<c) t=c; printf("The three numbers are:%d,%d,%d",a,b,c); printf("The max number is:%d",t); return 0; }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯