zoukankan      html  css  js  c++  java
  • C语言:将3*4矩阵中找出行最大,列最小的那个元素。-将低于平均值的人数作为函数返回值,将低于平均分的分数放入below数组中。

    //将3*4矩阵中找出行最大,列最小的那个元素。

     1 #include  <stdio.h>
     2 #define   M   3
     3 #define   N   4
     4 void fun(int  (*a)[N])
     5 { int  i=0,j,find=0,rmax,c,k;
     6   while( (i<M) && (!find))//这里发现i没有进行递增操作。
     7   {  rmax=a[i][0];  c=0;
     8      for(j=1; j<N; j++)
     9        if(rmax<a[i][j]) {
    10 /**********found**********/
    11          rmax=a[i][j]; c= j ; }//找出行最大的,并把列数赋予c。
    12      find=1; k=0;//设置标志位find
    13      while(k<M && find) {
    14 /**********found**********/
    15        if (k!=i && a[k][c]<=rmax)  find= 0 ;//不是这一列最小的。
    16        k++;
    17      }
    18      if(find) printf("find: a[%d][%d]=%d
    ",i,c,a[i][c]);
    19 /**********found**********/
    20       i++ ;//下一次循环
    21   }
    22   if(!find) printf("not found!
    ");
    23 }
    24 void main()
    25 { int  x[M][N],i,j;
    26   printf("Enter number for array:
    ");
    27   for(i=0; i<M; i++)
    28     for(j=0; j<N; j++) scanf("%d",&x[i][j]);
    29   printf("The array:
    ");
    30   for(i=0; i<M; i++)
    31   {  for(j=0; j<N; j++) printf("%3d",x[i][j]);
    32      printf("
    
    ");
    33   }
    34   fun(x);
    35 }

    //m个人的成绩存放在数组中,fun函数功能:将低于平均值的人数作为函数返回值,将低于平均分的分数放入below数组中。

     1 #include <conio.h>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 int fun(int score[],int m, int below[])
     6 {
     7     int i = 0,avg,sum=0,s=0,j=0;
     8     for (i; i < m; i++)
     9     {
    10         sum += score[i];
    11     }
    12     avg = sum / m;
    13     for (i = 0; i < m; i++)
    14     {
    15         if (score[i] < avg)
    16         {
    17             below[j++] = score[i];
    18             s++;
    19         }
    20     }
    21     return s;
    22 }
    23 void main()
    24 {
    25   FILE *wf;
    26   int i, n, below[9];
    27   int score[9]={10,20,30,40,50,60,70,80,90};
    28   system("CLS");
    29   n=fun(score, 9, below);
    30   printf("
    Below the average score are: ");
    31   for(i=0;i<n;i++)  
    32      printf("%d ",below[i]);
    33 /******************************/
    34   wf=fopen("out.dat","w");
    35   for(i=0;i<n;i++)  
    36      fprintf(wf,"%d ",below[i]);
    37   fclose(wf);
    38 /*****************************/
    39 }
  • 相关阅读:
    SpringMVC 配置式开发-HandlerMapping的执行流程(八)
    SpringMVC 配置式开发-BeanNameUrlHandlerMapping(七)
    SpringMVC路径问题回顾,加斜杠和不加斜杠的问题(六)
    web.xml 注册中央调度器Url-pattern 要注意的地方(五)
    SpringMVC执行流程(四)
    Spring 特点
    monkeyrunner操作多个设备的例子
    ant安装、环境变量配置及验证
    二进制、十六进制转换表
    Android源码开发利器——Java源码调试(基于4.1.2)
  • 原文地址:https://www.cnblogs.com/ming-4/p/10478827.html
Copyright © 2011-2022 走看看