main()
{
int a[10];//你定义的数组a[9]小了,它的范围是a[0]到a[8],只能装8个数
int max;
int b;
cout<<"输入10个大于0的数"<<endl;
for(int i=0;i<10;i++)
{
cin>>b;
a[i]=b;
}
max=a[0];//你的max没有赋值就使用了
for(int j=1;j<10;j++)//你的j没有赋值就使用了
{
if(max<=a[j])
max=a[j];
}
cout<<max;
}作者: 爱你 时间: 2009-11-3 04:01
谢谢大家~作者: √wo 时间: 2009-11-3 04:01
程序代码:
/*========================================
Must save as *.cpp, or else it is wrong.
Designer:suixin
QQ group: 21035626
Data:1-26-2008 15:30
========================================*/
#include <stdio.h>
#include <stdlib.h>
#define N 3
int max (int x, int y)
{
return x > y ? x : y;
}
int max (int x, int y, int z)
{
return max(max(x, y), z);
}
int max (int a, int b, int c, int d)
{
return max(max(a, b, c), d);
}
int max (int a, int b, int c, int d, int e)
{
return max(max(a, b, c, d), e);
}
int max (int a[], int len)
{
int ix = 0, max = a[ix];
for ( ; ix != len; ++ix)
{
if (a[ix] >= max)
{
max = a[ix];
}
}
return max;
}
int main()
{
//example1: maxterm in ten numbers
int a, b, c, d, e, f, g, h, i, j;
scanf("%d%d%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j);
printf("max:%d\n", max (max(a, b, c, d, e), max(f, g, h, i, j)));
//example2: maxterm in one arrary
int n[N] = {8, 9, 10};
printf("max:%d\n", max(n, N));
system("pause");
return 0;
}