標(biāo)題:
c語言數(shù)組元素做函數(shù)實(shí)參
[打印本頁]
作者:
liuda
時(shí)間:
2015-1-22 02:13
標(biāo)題:
c語言數(shù)組元素做函數(shù)實(shí)參
本帖最后由 liuda 于 2015-1-22 02:17 編輯
//這個(gè)程序應(yīng)該不難,我想先自己試試
#include<stdio.h>
void main()
{int a[10],b[10],m,n,da=0,xiao=0,deng=0,l,k;
int cmp(int x,int y);
//各有10個(gè)元素,逐個(gè)比較統(tǒng)計(jì)<,>,==次數(shù)
printf("please input the elements of a[10]\n");
for(m=0;m<=9;m++)
{
scanf("%d",&a[m]);
}
printf("please input the elements of b[10]\n");
for(n=0;n<=9;n++)
{
scanf("%d",&b[n]);
}
for(k=0;k<=9;k++)
{l=cmp(a[k],b[k]);
if(l==1)
da++;
else if(l==0)
deng++;
else
xiao++;}
printf("a[i]>b[i]=%d times\na[i]<b[i]=%d time\nsa[i]==b[i]=%d times\n",da,xiao,deng);
if(da>xiao)
printf("a is bigger\n");
else if(da<xiao)
printf("b is bigger\n");
else
printf("a ==b\n");}
int cmp(int x,int y)
{int z;
if(x>y)
z=1;
else if(x<y)
z=-1;
else
z=0;
return(z);
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1