鱼C论坛

 找回密码
 立即注册
查看: 3266|回复: 3

[复制链接]
发表于 2012-4-6 17:22:49 | 显示全部楼层 |阅读模式
1鱼币
/********************************************************************************************************************  
*  题目:                          *
*  给定程序blank1.c中,函数fun的功能是:在3行4列的矩阵中找出在行上最大、在列上最小的那个元素,     *
*  若没有符合条件的元素则输出相应信息。                  *
*  例如,有下列矩阵:                       *
*    1    2    13    4                     *
*    7    8    10    6                     *
*    3    5    9    7                     *
*  程序执行结果为:find: a[2][2]=9                    *
*                             *
*  答题提示:请先将程序中的“__1__、__2__、__3__”删除,在相应的位置填入正确的答案。最后将答案写到试卷上。  *
*********************************************************************************************************************/
#include <stdio.h>
#define   M   3
#define   N   4
void fun(int (*a)[N])
{  int i=0,j,find=0,rmax,c,k;
while( (i<M) && (!find))
{  rmax=a[i][0]; c=0;
    for(j=1; j<N; j++)
       if(rmax<a[i][j]) {
/**********found**********/
          rmax=a[i][j]; c=___1___ ; }
    find=1; k=0;
    while(k<M && find)
{
/**********found**********/
        if (k!=i && a[k][c]<=rmax) find=___2___ ;
k++;
     }
     if(find) printf("find: a[%d][%d]=%d\n",i,c,a[i][c]);
/**********found**********/
    ___3___;
}
if(!find) printf("not found!\n");
}
main()
{  int x[M][N],i,j;
printf("Enter number for array:\n");
for(i=0; i<M; i++)
    for(j=0; j<N; j++) scanf("%d",&x[i][j]);
printf("The array:\n");
for(i=0; i<M; i++)
{  for(j=0; j<N; j++) printf("%3d",x[i][j]);
    printf("\n\n");
}
fun(x);
}

最佳答案

查看完整内容

c=j; //___1___ find=0; //___2___ i++; //____3____
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-4-6 17:22:50 | 显示全部楼层
c=j;       //___1___
find=0;  //___2___
i++;      //____3____


  1. #include <stdio.h>
  2. #define   M   3
  3. #define   N   4
  4. void fun(int (*a)[N])
  5. {  
  6. int i=0,j,find=0,rmax,c,k;
  7.     while( (i<M) && (!find))
  8. {  rmax=a[i][0]; c=0;
  9.        for(j=1; j<N; j++)
  10.          if(rmax<a[i][j])
  11.    {
  12.       /**********found**********/
  13.          rmax=a[i][j]; c=j ;
  14.    }
  15.        find=1; k=0;
  16.        while(k<M && find)
  17.     {
  18.        /**********found**********/
  19.       if (k!=i && a[k][c]<=rmax)
  20.     find=0 ;
  21.       k++;
  22.     }
  23.        if(find)
  24.     printf("find: a[%d][%d]=%d\n",i,c,a[i][c]);
  25.           /**********found**********/
  26.           i++;
  27. }
  28.      if(!find)
  29.    printf("not found!\n");
  30. }
  31. int main()
  32. {  int x[M][N],i,j;
  33.    printf("Enter number for array:\n");
  34.    for(i=0; i<M; i++)
  35.       for(j=0; j<N; j++)
  36.    scanf("%d",&x[i][j]);
  37.    printf("The array:\n");
  38.     for(i=0; i<M; i++)
  39. {  
  40.   for(j=0; j<N; j++)
  41.    printf("%3d",x[i][j]);
  42.          printf("\n\n");
  43. }
  44. fun(x);
  45. return 0;
  46. }
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-4-9 18:16:07 | 显示全部楼层
。。。。 谢谢···
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-4-10 00:09:46 | 显示全部楼层
走过看看,这里的高手还真不少啊。呵呵
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-12 15:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表