猎场首播盛典发布会:用c语言编程,求任意10个数中的最大数与最小数之和。

来源:百度文库 编辑:高校问答 时间:2024/04/29 10:49:38
各位高手帮帮我吧!!!!!!!!!!

现场 来 一个
void main()
{
int i;
int e;
int r;
int s;
int a[10];

printf("please input the nums!\n");
scanf("%d%d%d%d%d%d%d%d%d%d\n",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
for(e=0;e<9;e++)
for(i=0;i<(9-e);i++)
if (a[i]>a[i+1]){
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}

s=a[0]+a[9];
printf("%d",s);
}

#include <stdio.h>

int main( int argc, char *argv[] )
{
int i, min_num, max_num , a[10] = { 8, 7, 9, 4, 1, 8, 3, 12, 9, 15 };

min_num = a[0];
max_num = a[1];

for ( i = 0; i < 10; i++ )
{
if ( a[i] > max_num )
{
max_num = a[i];
}
else if ( a[i] < min_num )
{
min_num = a[i];
}
}

printf( "%d\n", max_num + min_num );

return 0;
}

用不着排序。。。。

int sum(int list[])
{
int tempMax = list[0];
int tempMin = list[0];
for (int i = 0; i < 10; ++i)
{
if (tempMin > list[i])
tempMin = list[i];
else
if (tempMax < list[i])
tempMax = list[i];
}
return (tempMax + tempMin);
}

大哥你不会吧,最简单的啊

先排序结果存入一个数组再把首尾两个元素加起来就行