標(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 編輯

  1. //這個(gè)程序應(yīng)該不難,我想先自己試試
  2. #include<stdio.h>
  3. void main()
  4. {int a[10],b[10],m,n,da=0,xiao=0,deng=0,l,k;
  5. int cmp(int x,int y);
  6. //各有10個(gè)元素,逐個(gè)比較統(tǒng)計(jì)<,>,==次數(shù)
  7. printf("please input the elements of a[10]\n");
  8. for(m=0;m<=9;m++)
  9. {
  10. scanf("%d",&a[m]);
  11. }
  12. printf("please input the elements of b[10]\n");
  13. for(n=0;n<=9;n++)
  14. {
  15. scanf("%d",&b[n]);
  16. }
  17. for(k=0;k<=9;k++)
  18. {l=cmp(a[k],b[k]);
  19. if(l==1)
  20. da++;
  21. else if(l==0)
  22. deng++;
  23. else
  24. xiao++;}
  25. printf("a[i]>b[i]=%d times\na[i]<b[i]=%d time\nsa[i]==b[i]=%d times\n",da,xiao,deng);
  26. if(da>xiao)
  27. printf("a is bigger\n");
  28. else if(da<xiao)
  29. printf("b is bigger\n");
  30. else
  31. printf("a ==b\n");}

  32. int cmp(int x,int y)
  33. {int z;
  34. if(x>y)
  35. z=1;
  36. else if(x<y)
  37. z=-1;
  38. else
  39. z=0;
  40. return(z);
  41. }
復(fù)制代碼







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1