| 
 | 
 
 
发表于 2018-12-16 14:59:41
|
显示全部楼层
 
 
 
- #include <stdio.h>
 
 - #include <stdlib.h>
 
 - #include <windows.h>
 
  
- POINT ArrayMax(size_t array[], size_t size)
 
 - {
 
 -         POINT pos = {0, 0};
 
 -         for(size_t y = 0; y < size; ++y)
 
 -         {
 
 -                 for(size_t x = 0; x < size; ++x)
 
 -                 {
 
 -                         size_t value = array[pos.y * size + pos.x];
 
 -                         if(value < array[y * size + x])
 
 -                         {
 
 -                                 pos.x = x;
 
 -                                 pos.y = y;
 
 -                         }
 
 -                 }
 
 -         }
 
 -         return pos;
 
 - }
 
  
- void ArrayInput(size_t array[], size_t size)
 
 - {
 
 -         for(size_t y = 0; y < size; ++y)
 
 -         {
 
 -                 for(size_t x = 0; x < size; ++x)
 
 -                 {
 
 -                         size_t value;
 
 -                         printf("[%u,%u]=", y, x);
 
 -                         scanf("%u", &value);
 
 -                         array[y * size + x] = value;
 
 -                 }
 
 -         }
 
 - }
 
  
- int main(void)
 
 - {
 
 -         size_t size;
 
 -         printf("N=");
 
 -         scanf("%u", &size);
 
  
-         size_t *data = malloc(sizeof(size_t) * size * size);
 
 -         ArrayInput(data, size);
 
 -         POINT pos = ArrayMax(data, size);
 
 -         printf("Max=[%u,%u]=%u\n", pos.x, pos.y, data[pos.y * size + pos.x]);
 
 -         free(data);
 
 -         
 
 -         return 0;
 
 - }
 
 
  复制代码 
- N=5
 
 - [0,0]=26
 
 - [0,1]=36
 
 - [0,2]=734
 
 - [0,3]=12
 
 - [0,4]=35
 
 - [1,0]=89
 
 - [1,1]=43
 
 - [1,2]=32
 
 - [1,3]=72
 
 - [1,4]=15
 
 - [2,0]=10
 
 - [2,1]=9
 
 - [2,2]=25
 
 - [2,3]=6
 
 - [2,4]=27
 
 - [3,0]=64
 
 - [3,1]=2
 
 - [3,2]=73
 
 - [3,3]=745
 
 - [3,4]=2
 
 - [4,0]=36
 
 - [4,1]=654
 
 - [4,2]=6
 
 - [4,3]=3
 
 - [4,4]=23
 
 - Max=[3,3]=745
 
 - 请按任意键继续. . .
 
 
  复制代码 |   
 
 
 
 |