Advertisement
Josif_tepe

Untitled

Jun 6th, 2024
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5.  
  6. int main() {
  7.    int n, m;
  8.    scanf("%d%d", &n, &m);
  9.  
  10.    float mat[n][m];
  11.    for(int i = 0; i < n; i++) {
  12.     for(int j = 0; j < m; j++) {
  13.         scanf("%f", &mat[i][j]);
  14.     }
  15.    }
  16.    float x;
  17.    scanf("%f", &x);
  18.  
  19.    for(int i = 0; i < n; i++) {
  20.     float najmal = fabs(x - mat[i][0]);
  21.     for(int j = 0; j < m; j++) {
  22.         if(fabs(x - mat[i][j]) < najmal) {
  23.             najmal = fabs(x - mat[i][j]);
  24.         }
  25.    
  26.     }
  27.     printf("%f\n", najmal);
  28.     printf("Redica %d i kolona: ", i);
  29.     for(int j = 0; j < m; j++) {
  30.         if(najmal == fabs(x - mat[i][j])) {
  31.             printf("%d ", j);
  32.         }
  33.     }
  34.     printf("\n");
  35.    }
  36.  
  37. }
  38. /*
  39. 4 4
  40. 1.7 2.0 7.1 1.9
  41. 7.3 2.2 3.4 1.01
  42. 6.0 5.1 5.2 4.1
  43. 4.4 1.0 0.0 1.2
  44. 4.5
  45.  
  46. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement