c++ - Find the smallest number in an array and the position it is -


i have code, , want find smallest number , in position in array 3x3,how do that?

#include <stdio.h> int main()  {     int a[3][3];   int i,j;   int min; min=0; for(i=0;i<3;i++)     {     printf("\n");     for(j=0;j<3;j++)     {         scanf("%d",&a[i][j]);     } } for(i=0;i<3;i++) {     for(j=0;j<3;j++)     {         if(a[i][j]>=min)             min=a[i][j];     }     printf("\n");         printf("%d\n",min); } 

}

try this

#include < stdio.h > #include < limits.h >  int main() {     int a[3][3];     int i, j;     (i = 0; < 3; i++) {         printf("\n");         (j = 0; j < 3; j++) {             scanf("%d", &a[i][j]);         }     }      int min = int_max, y = -1, x = -1;     (i = 0; < 3; i++) {         (j = 0; j < 3; j++) {             if (a[i][j] < min) {                 min = a[i][j];                 y = i;                 x = j;             }              printf("%d ", a[i][j]);         }         printf("\n");     }      printf("minimum %d, located @ %d, %d\n", min, y, x); } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -