#includestdio.h
創(chuàng)新互聯(lián)建站主營永新網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,重慶APP開發(fā)公司,永新h5小程序定制開發(fā)搭建,永新網(wǎng)站營銷推廣歡迎永新等地區(qū)企業(yè)咨詢
int max(int a[])
{
int i,m=a[0];
for(i=0;i5;i++)
if(ma[i])m=a[i];
return m;
}
main()
{
int a[5],i;
printf("input 5 numbers:\n");
for(i=0;i5;i++)
scanf("%d",a[i]);
printf("the max:%d\n",max(a));
}
#include stdio.h
int main()
{
int a[5],max,i;
for(i=0;i5;i++)
scanf("%d",a[i]);
max=a[0];
for(i=1;i5;i++)
if(maxa[i])
max=a[i];
printf("最大數(shù)為:%d\n",max);
return 0;
}
呵呵,gap12521 太可愛了,不用那么麻煩的
#include?stdio.h
int?main()
{
int?a1,a2,a3,a4,a5,max;
printf("輸入5個數(shù)的值:?");
scanf("%d%d%d%d%d",a1,a2,a3,a4,a5);
max=a1;
if(maxa2)
max=a2;
if(maxa3)
max=a3;
if(maxa4)
max=a4;
if(maxa5)
max=a5;
printf("5個數(shù)中的最大值為:?%d\n",max);
return?0;
}
示例運行結果:
輸入5個數(shù)的值: 12 36 5 88 64
5個數(shù)中的最大值為: 88
#include<iostream>
usingnamespacestd;
int main()
{
int a,b,c;
cout<<"輸入五個整數(shù)";
cin>>a>>b>>c;
if(a>b)
{
if(c>a)
cout<<"最大整數(shù)是:"<<c<<endl;
else
cout<<"最大整數(shù)是:"<<a<<endl;
}
if(b>a)
{
if(c>b)
cout<<"最大整數(shù)是:"<<c<<endl;
else
cout<<"最大整數(shù)是:"<<b<<endl;
}
return0;
}
舉例:
輸入三個數(shù):
12 45 32
輸出最大數(shù):
45
擴展資料:
printf()用法:
1、printf()函數(shù)是格式化輸出函數(shù),一般用于向標準輸出設備按規(guī)定格式輸出信息。
格式輸出,它是c語言中產(chǎn)生格式化輸出的函數(shù)(在stdio.h中定義)。用于向終端(顯示器、控制臺等)輸出字符。格式控制由要輸出的文字和數(shù)據(jù)格式說明組成。
要輸出的文字除了可以使用字母、數(shù)字、空格和一些數(shù)字符號以外,還可以使用一些轉(zhuǎn)義字符表示特殊的含義。
簡單點理解就是,在一段程序中你正確使用該函數(shù),可以在該程序運行的時候輸出你所需要的內(nèi)容。
2、printf函數(shù)是一個標準庫函數(shù),它的函數(shù)原型在頭文件“stdio.h”中。但作為一個特例,不要求在使用printf函數(shù)之前必須包含stdio.h文件。
printf()函數(shù)的調(diào)用格式為:printf("lt;格式化字符串gt;",lt;參量表gt;)。
其中格式化字符串用于指定輸出格式。格式控制串可由格式字符串和非格式字符串兩種組成。
思路:條件運算符求最大數(shù)可以表示成:ab?a:b,求的就是a和b中的最大數(shù)。本題可以先求出前兩個數(shù)的最大值賦值給第一個數(shù),接著依次和第三個、第四數(shù)比較,求出最大數(shù)并輸出。
參考代碼:
#include
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",a,b,c,d);
a=ab?a:b;
a=ac?a:c;
a=ad?a:d;
printf("最大值為:%d\n",a);
return 0;
}
/*
5 1 7 3
最大值為:7
*/
#include stdio.h
int get_max(int a[], size_t len)
{
int i;
int max;
max = a[0];
for (i = 1; i len; i++)
{
if (a[i] max)
{
max = a[i];
}
}
return max;
}
int main(int argc, char *argv[])
{
int a[5] = {7, 0, 5, 34, 8};
int max;
max = get_max(a, sizeof(a));
printf("max = %d\n", max);
return 0;
}
網(wǎng)站標題:c語言求五個數(shù)最大的函數(shù) c語言求幾個數(shù)中的最大數(shù)
標題鏈接:http://chinadenli.net/article48/doddshp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設、虛擬主機、品牌網(wǎng)站建設、手機網(wǎng)站建設、網(wǎng)站制作、面包屑導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)