编程题:查找数组中最大的元素值
array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
#include <stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main(void) { int array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 },max=array[0]; for (int i = 1; i < 10; i++) { if (max < array[i]) { max = array[i]; } } puts("数组元素最大值为:"); printf("%d\n", max); return 0; }
#include<iostream>
using namespace std;
int getMaximum(int * array,int length)
{
if(length==1)
return *array;
}
int temporary=getMaximum(array+1,length-1);
return *array>temporary?*array:temporary;
int main()
int array[10]={19,20,360,1413,95,7,8,9,0};
int length=sizeof(array)/sizeof(int);
cout<<getMaximum(array,length);
#include <stdi...
用户登录可进行刷题及查看答案
#include <stdio.h> int main() { int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int loop, largest; largest = array[0]; for(loop = 1; loop < 10; loop++) { if( largest < array[loop] ) largest = array[loop]; } printf("最大元素为 %d", largest); return 0; }
登录后提交答案