本帖最后由 liuda 于 2015-1-22 02:17 編輯
- //這個程序應該不難,我想先自己試試
- #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個元素,逐個比較統計<,>,==次數
- 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);
- }
復制代碼
|