在C中找到最大和最小的整数
发布时间:2020-12-16 03:06:45 所属栏目:百科 来源:网络整理
导读:正如我在另一个问题中提到的,我一直在从C.N King的C编程:现代方法(2ndEdn)中教出自己. 我很喜欢,但希望在适当的情况下发布这个奇怪的问题,因为不幸的是我没有导师,有些提出更多的问题,然后他们回答! 我想要一个问题,要求我写一个程序,发现用户输入的最大和
正如我在另一个问题中提到的,我一直在从C.N King的C编程:现代方法(2ndEdn)中教出自己.
我很喜欢,但希望在适当的情况下发布这个奇怪的问题,因为不幸的是我没有导师,有些提出更多的问题,然后他们回答! 我想要一个问题,要求我写一个程序,发现用户输入的最大和最小的四个整数…我想出了一种找到最大的整数的方法,但是对于我的生活不了解如何最小化.这个问题说,四个if语句应该是足够的.数学不是我的老板,我会感谢任何建议! #include <stdio.h> int main(int argc,const char *argv[]) { int one,two,three,four; printf("Enter four integers: "); scanf("%d %d %d %d",&one,&two,&three,&four); if (four > three && four > two && four > one) printf("Largest: %d",four); else if (three > four && three > two && three > one) printf("Largest: %d",three); else if (two > three && two > four && two > one) printf("Largest: %d",two); else printf("Largest: %d",one); return 0; } 我想保持简单,因为我只能按照第27章的第5章! 干杯 解决方法if (first > second) swap(&first,&second); if (third > fourth) swap(&third,&fourth); if (first > third) swap(&first,&third); if (second > fourth) swap(&second,&fourth); printf("Smallest: %dn",first); printf("Largest: %dn",fourth); swap()函数的实现被保留为运动. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |