用C语言编写一个程序,求n个数中的最大值和最小值,要求用函数完成。 c语言编程实现某一个数组中最大值,最小值之和。并要求最大最小...
\u6c42c\u8bed\u8a00\u7a0b\u5e8f\uff1a\u7528\u4e00\u4e2a\u51fd\u6570\u6c42N\u4e2a\u6570\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u3002\u3002@
741852963\u4e00
\u697c\u4e0a\u7684\u670b\u53cb\uff0c\u5bf9\u4e8e\u4f60\u7ed9\u7684\u7b54\u6848\uff0c\u6211\u60f3\u8bf4\u70b9\u6211\u81ea\u5df1\u7684\u60f3\u6cd5\uff0c\u671b\u4e0d\u8981\u89c1\u602a\u3002
1.
LZ\u8981\u7684\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u9700\u8981\u5728main
\u51fd\u6570\u4e2d\u8fdb\u884c\u8c03\u7528\uff0c\u800c\u4e0d\u662f\u8981\u5b8c\u6574\u7684main\u51fd\u6570\u3002
2.
LZ\u8981\u7684\u51fd\u6570\u529f\u80fd\u53ea\u8981\u6c42
\u6c42\u51fa\u6700\u5927\u503c\u8ddf\u6700\u5c0f\u503c\uff0c\u800c\u4e0d\u9700\u8981\u6392\u5e8f\u3002
3\u3002\u4f60\u7684\u7a0b\u5e8f\u4e2d\u7528\u7684\u662fa[10]\uff0c\u4f46n
\u662f\u53ef\u4ee5\u968f\u4fbf\u8f93\u5165\u7684\uff0c\u8fd9\u5c31\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff1a
n
\u8981\u662f\u5927\u4e8e10\u65f6\uff0c
a[n]
\u5c31\u4f1a\u6ea2\u51fa\u3002
\u4e0b\u9762\u662f\u6211\u7f16\u5199\u7684\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5f53\u7136\u6211\u4e0d\u80fd\u4fdd\u8bc1\u5b83\u662f\u5b8c\u5168\u6b63\u786e\u7684\uff0c\u5e0c\u671b\u5927\u5bb6\u63d0\u610f\u89c1\u3002
float
fun(int
N,
float
a[
])
{
int
i;
float
max,
min;
max=min=a[0];
for
(i=1;i<N;i++)
{
if
(a[i]>=max)
max=a[i];
if
(a[i]<=min)
min=a[i];
}
prinft("max=
"
%f
",
min=
"
%f,
max,min);
return
0;
}
#include
//\u3001\u3001c\u8bed\u8a00\u7f16\u7a0b\u5b9e\u73b0\u67d0\u4e00\u4e2a\u6570\u7ec4\u4e2d\u6700\u5927\u503c,\u6700\u5c0f\u503c\u4e4b\u548c\u3002\u5e76\u8981\u6c42\u6700\u5927\u6700\u5c0f\u503c\u7528\u5b50\u51fd\u6570\u5b9e\u73b0
int Max(int a[], int n);
int Min(int a[], int n);
int Sum(int a, int b);
int main( )
{
int a[10];
int i;
printf("\u8bf7\u8f93\u516510\u4e2a\u6570:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &a[i]);
}
printf("sum = %d\n",Sum(Max(a, 10), Min(a, 10)));
return 0;
}
int Max(int a[], int n)
{
int i;
int max = a[0];
for (i = 0; i < 10; i++) {
if (max < a[i]) {
max = a[i];
}
}
return max;
}
int Min(int a[], int n)
{
int i;
int min = a[0];
for (i = 0; i < 10; i++) {
if (min > a[i]) {
min = a[i];
}
}
return min;
}
int Sum(int a, int b)
{
return a + b;
}
代码如下(用冒泡排序法):
#include <stdio.h>
void bubble(int a[], int n)
{
int i, j, temp;
for (j = 0; j < n - 1; j++)
for (i = 0; i < n - 1 - j; i++)
{
if(a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
int main(void)
{
int a[10];
for(int i = 0; i < 10; i++)
scanf("%d", &a[i]);
bubble(a, 10);
printf("Max: %d, min: %d", a[9], a[0]);
return 0;
}
#include<stdio.h>
#define N 1024
void fun(int *a,int n,int *max,int *min) { int i;
*max=*min=a[0];
for ( i=1;i<n;i++ ) if ( *max<a[i] ) *max=a[i]; else if ( *min>a[i] ) *min=a[i];
}
void main() { int i,n,max,min,a[N];
scanf("%d",&n); if ( n>N ) n=N;
for ( i=0;i<n;i++ ) scanf("%d",&a[i]);
fun(a,n,&max,&min);
printf("最大值=%d,最小值=%d。
",max,min);
}
绛旓細鎬濊矾锛氶鍏堣缃渶澶ф渶灏忕殑鍊奸兘鏄暟缁勭涓涓暟锛岀劧鍚庨亶鍘嗘暟缁勶紝鍑虹幇姣斿綋鍓嶆渶澶у煎ぇ鐨勶紝淇敼鏈澶у间负杩欎釜鏁銆傚嚭鐜版瘮鏈灏忓煎皬鐨勶紝淇敼鏈灏忓间负杩欎釜鏁般備唬鐮 include <stdio.h>//涓轰簡鏂逛究杩斿洖锛屼娇鐢ㄧ粨鏋勪綋瀛樺偍鏈澶у煎拰鏈灏忓紅ypedef struct { int Max; int Min;}MaxMin; //鍑芥暟鍙傛暟array锛氭暟缁...
绛旓細include<stdio.h>int max(int n){int i,x,f; scanf("%d",&f); for(i=1;i<n;i++) {scanf("%d",&x); if(x>f)f=x; } return f;}int main(){int n; printf("鏈夊嚑涓暟:"); scanf("%d",&n); printf("鍏朵腑鏈澶х殑鏁版槸锛%d\n",max(n)); return 0;} include<stdio...
绛旓細```c include <stdio.h> int main() { int n, i;int arr[100], max; //瀹氫箟鏁村瀷鏁扮粍鍜屾渶澶у煎彉閲 printf("璇疯緭鍏ュ厓绱犱釜鏁帮紙涓嶈秴杩100锛夛細");scanf("%d", &n);printf("璇疯緭鍏%d涓暟瀛锛", n);for (i = 0; i < n; i++) { scanf("%d", &arr[i]);} max = arr[0];...
绛旓細```c include <stdio.h> int main() { int n, i, j, sum;printf("璇疯緭鍏ヤ竴涓鏁鏁皀锛");scanf("%d", &n);for (i = 1; i <= n; ++i) { sum = 0;for (j = 1; j <= i / 2; ++j) { if (i % j == 0) { sum += j;} } if (sum == i) { printf(...
绛旓細鐢╟璇█缂栧啓涓涓▼搴锛氬浜庝竴涓嚜鐒鏁皀(n<=50),缁熻鍏锋湁涓嬪垪鏁板瓧鐨涓暟锛屽苟杈撳嚭鎵鏈夌鍚堟潯浠剁殑鏁板瓧锛氳嚜鐒舵暟n锛屽湪n鐨勫乏杈瑰姞涓婁竴涓嚜鐒舵暟锛屼絾璇ヨ嚜鐒舵暟涓嶈兘瓒呰繃鍘熸暟鐨勪竴鍗婏紱缁х画鎸夋瑙勫垯杩涜澶勭悊锛岀洿鍒颁笉鑳藉姞鑷劧鏁颁负姝備緥濡傚綋n=6鏃讹紝绗﹀悎鏉′欢鏉′欢鐨勬槸锛6,16,26,36,126,136鍏6涓紱褰搉=5鏃讹紝...
绛旓細浠ヤ笅鏄竴涓畝鍗曠殑C璇█绋嬪簭锛鐢ㄤ簬杈撳叆N涓鏁存暟骞舵眰鍜岋細鍦ㄨ繖涓▼搴忎腑锛屾垜浠鍏堝畾涔変簡涓や釜鏁村瀷鍙橀噺num鍜孨锛岀敤浜庡瓨鍌ㄧ敤鎴疯緭鍏ョ殑鏁板拰鏁扮殑涓暟銆傜劧鍚庯紝鎴戜滑浣跨敤printf鍑芥暟杈撳嚭鎻愮ず淇℃伅锛屼娇鐢╯canf鍑芥暟浠庣敤鎴峰璇诲彇鏁扮殑涓暟N銆傜劧鍚庯紝鎴戜滑浣跨敤if璇彞妫鏌鏄惁鍦ㄦ湁鏁堣寖鍥村唴锛堝ぇ浜0涓斿皬浜庢垨绛変簬100锛夈傚鏋淣涓嶅湪...
绛旓細//鐢–璇█缂栧啓绋嬪簭锛氳緭鍏n涓暟锛屾眰鍑烘渶灏忕殑锛屽苟姹傚嚭涓虹鍑犱釜銆俰nclude<stdio.h> int main(){ int i, n, m = 0, num, min;scanf("%d", &n); //鍒濆鍖栬緭鍏ユ暟瀛椾釜鏁皀 for(i = 0; i < n; i++){ scanf("%d", &num); //杈撳叆n涓暟瀛 if(i == 0) //鍒濆鍖栨渶...
绛旓細for(i=0;i<n;i++){ printf("绗%d涓鐢:\n",i+1);stud[i].mc=i+1;printf("杈撳叆瀛﹀彿:");scanf("%d",&stud[i].number);printf("杈撳叆濮撳悕:");scanf("%s",stud[i].name);printf("杈撳叆鏁板鎴愮哗:");scanf("%lf",&stud[i].math);printf("杈撳叆鑻辫鎴愮哗:");scanf("%lf",&...
绛旓細鍙互鍙傝冧笅闈㈢殑浠g爜锛歩nclude <stdio.h> void main( ){ int n, i, num , max ;scanf("%d", &n);scanf("%d", &num);max=num;for(i = 1; i < n; i++){ scanf("%d", &num);if(max < num)max = num;} printf("%d\n", max);} ...
绛旓細scanf("%d",&x);//瑕佹彃鍏ョ殑鏁 sort1(a,n);//璋冪敤鍑芥暟閫夋嫨鎺掑簭 for(int i=0;i<n;i++)printf("%d ",a[i]);//杈撳嚭绗竴娆℃帓搴忕殑缁撴灉 printf("\n");sort2(a,n,x);//璋冪敤鍑芥暟鍏堟彃鍏涓涓暟锛鐒跺悗鎺掑簭 for(int i=0;i<n+1;i++)printf("%d ",a[i]); //杈撳嚭绗簩娆℃帓搴忕殑...