谁帮忙用C++写个程序“读取5个整数并确定和打印其中的最大值”。要能够运行啊

2025-01-02 11:04:15
推荐回答(3个)
回答1:

#include
using namespace std;

void main() //测试用例
{
int values[5], maxval, position;

cout<<"请输入5个整数,以空格隔开:";
cin>>values[0] >> values[1] >>values[2] >>values[3] >>values[4] ;

position = 0;
maxval = values[0];
for (int index = 0; index < 5; index++)
{
if (maxval < values[index])
{
position = index;
maxval = values[index];
}
}

cout<<"最大值为"< system("pause");
}

回答2:

#include "stdafx.h"

int get_maxval(int *valarry, int elem_num)
{
if(NULL == valarry)
return -1;

int max = valarry[0];

for(int i=1;i {
max = (max }

return max;
}

int _tmain(int argc, _TCHAR* argv[])
{
int buf[5] = {0};

//require the user to input the value
for(int i=0;i<5;i++)
{
printf("Please your int type number-NO.%d:\n",i+1);
scanf("%d",buf+i);
}

//get the max one
int max_num = get_maxval(buf, sizeof(buf)/sizeof(int));

//printf the result
printf("The max value is:%d\n",max_num);

return 0;
}

回答3:

t;a;
cin>>b;
if(a>b) cout<else if(a==b) cout<<"these numbers are equal";
else cout<
2.cout<<"Input three different intergers:";
int a,b,c;
cin>>a;
cin>>b;
cin>>c;
while(a==b||a==c||b==c)
{
cout<<"the numbers must be different,please input again:";
cin>>a;
cin>>b;
cin>>c;
}
cout<<"Sum is "<cout<<"Average is "<<(double)(a+b+c)/(double)3<cout<<"Product is "<int sml,lag;
if(a{
if(a {
sml=a;
if(b else lag=b;
}
else
}
else{
if(a else
{
lag=a;
if(b>c) sml=c;
else sml=b;
}
}
cout<<"Smallest is "<cout<<"Lagest is "<3.
*
**
***
****
*****
4.
int num[5];
for(int i=0;i<5;i++)
{cin>>num[i];
}
int max=num[0],mark=0;
for(int i=1;i<5;i++)
{
if(num[i]>max)
}
cout<<"第"<5.int a;
cin>>a;
if(a%2==0) cout<<"是偶数"<else cout<<"是奇数"<