用c语言求一组数中最大值和最小值,用c语言求一组数组的最大值以及最小值

#include//stdio.h是c的标准的i/o库,是以函数的方式向buffer写入或读取字符,iostream.h是c++的标准i/o库,引入了输入/输出流的概念,是一个类库,是以类方法从streambuf中读取,写入字符。

int max=0;

int min=1000;

void change(int a[],int n)

{

int i,j,k;

for(i=1;imax)

{

max=a[i];

k=i;

}

a[k]=min;

a[j]=max;

printf("the position of min is:%3d\n",j);

printf("the position of max is:%3d\n",k);

printf("Now the array is:\n");

for(i=0;i

xiongyao@xiongyao-Lenovo:~/c编程$ gcc  example.c -o example

xiongyao@xiongyao-Lenovo:~/c编程$ ./example

please input the number of elements:

3

please imput the elements:

1

3

5

the position of min is:  0

the position of max is:  2

Now the array is:

5    3    1

max=5

min=1

第二种方法:

#include "stdio.h"

//从键盘输入10个数存入一维数组,求这10个数中的最大值和最小值并输出

int main()

{

int i;

float max,min,a[10];

printf("请输入10个数,每输入一个数按回车键结束:\n");

for(i=0;i<10;i++)

{

scanf("%f",&a[i]);

}

max=min=a[0];

for(i=1;i<10;i++)

{

if(maxa[i])

min=a[i];

}

printf("最大为:%f\n最小为:%f\n",max,min);

return 0;

}

xiongyao@xiongyao-Lenovo:~/c编程$ gcc 2.c -o 2

xiongyao@xiongyao-Lenovo:~/c编程$ ./2

请输入10个数,每输入一个数按回车键结束:

1

3

6

5

9

23

56

95

45

8

最大为:95.000000

最小为:1.000000

xiongyao@xiongyao-Lenovo:~/c编程$

  • 5
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值