c++的问题我写的特小的程序,但老是有2个错误错误,望高手来帮忙。

来源:百度知道 编辑:UC知道 时间:2024/05/20 01:02:41
问题描述
程序提示用户输入5个整数,然后程序输出其中的最大值和最小值;
然后程序再提示用户输入3个整数,程序输出三个整数从大到小的排列。
输入输出
用户输入数据样例如下:
Please input five integers(a,b,c,d,e):
10, 4, 6,20,1
系统输出数据如下:
Max:20,Min:1
用户在输入三个整数:
Please input three integers(a,b,c,):
9,2,30
系统输出数据如下:
30,9,2

#include <stdio.h>
#include <math.h>
void main()
{
int a,b,c,d,e;

scanf("%d,%d,%d,%d,%d",&a,&b,&c,&d,&e);

if (a>b) && (a>c) && (a>d) && (a>e)
printf("max=%d\n",a);

else if (b>a) && (b>c) && (b>d) && (b>e)
printf("max=%d\n",b);

else if (c>a) && (c>b) && (c>d) && (c>e)
printf("max=%d\n",c);

else if (d>a) && (d>b) && (d>c) && (d>e)
printf("max=%d\n",d);

else
printf("max=%d\n",e);

#include <studio.h>
感觉描述的不大清楚,那就按我发现的给出了。下面是你写的代码:
void main ()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%d %d %d\n",a,b,c);
}
---------------------错误指出
<studio.h> 改为<stdio.h>
scanf("%d%d%d",&a,&b,&c);改为scanf("%d %d %d",&a,&b,&c);
*这样,连续输入三个数a、b、c,之间即可用空格隔开也可以用回车换行隔开

第一题,第一步你应该获取5个整形数,然后用程序求出最大最小值,保存在两个变量里,然后输出;第二步你还得获取3个整形数,对他们进行一下排序,然后输出;
第二题,scanf("%d%d%d",&a,&b,&c);这样不行,试想,你输入123的时候,程序会把它当成一个%d就接受的数。其实,直接用scanf("%d",&a),然后把a的各个位都加个空格输出就可以了,或者用字符串读入这个数,然后每个元素中间插个空格输出就行
第三题,你得这样写:
printf("Please input work time:\n");
scanf("%lf",&a);
printf("Please input the salary per hour:\n");
scanf("%lf",&b);
这样才能保证输出那两行提示信息。这样也可以分别获取a和b的值

printf("Please input work time:\n");
scanf("%d",&work_time);

printf("