请高手帮我写一下这个程序

会织网的蚂蚁 2007-11-04 02:53:28
随意输入几个数据,然后断定某个值最大,然后输出。最好能用函数。
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangxw000 2007-11-05
  • 打赏
  • 举报
回复
#include<stdio.h>
int max(int a[],int k)
{
int MAX=a[0],i;
for(i=0;i<k;i++)
if(a[i]>MAX)MAX=a[i];
return(MAX);
}
void main()
{
int a[100]={0},n,i;
printf("please input the number of intrger:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",a[i]);
for(i=0;i<n;i++)
printf("the max of the numbers is:\n",max(a,n));
}
.......
wzwmm 2007-11-04
  • 打赏
  • 举报
回复
lz说的MS是随意输入几个数据吧
试试这个

#include<iostream>
#include<vector>

using namespace std;

double Dind_Max(vector<double> A);

void main()
{
vector<double> B;

for(double i; cin>>i;)
B.push_back(i);

cout<<Dind_Max(B)<<endl;
}

double Dind_Max(vector<double> A)
{
double Max = A[0];

for(int j=1; j<=A.size(); j++)
{
if(A[j]>=A[0])
Max = A[j];
}

return Max ;

}

我也是菜鸟,献丑了
fly_6189 2007-11-04
  • 打赏
  • 举报
回复
一楼printf("%d\n",b);???
因该是printf("%d\n",a);把
楼主用不惯crtl+z可以考虑下改个结束标记
void max()
{
int a,b;
a=0;
printf("请输入你需要的数以-1结束\n");
scanf("%d",&b);
while(b!=-1)//-1结束输入
{
if(a<b)
a=b;
scanf("%d",&b);
}
printf("%d\n",a);
}
ping11235813 2007-11-04
  • 打赏
  • 举报
回复
ls的代码应该
printf("%d",a);
这样才对吧
guzhilei1986 2007-11-04
  • 打赏
  • 举报
回复
void find_max()
{
int a,b;
a=0;
while(scanf("%d",&b)!=EOF)//以crtl+z为结束符
{
if(a<b)
a=b;
}
printf("%d\n",b);
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧