Advertisement
PadmaJS

findvals.c

Oct 26th, 2022
1,926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "utils.c"
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.   struct tm *local;
  10.   time_t start, end;
  11.   time(&start);
  12.   local = localtime(&start);
  13.   printf("# Start time and date: %s", asctime(local));
  14.  
  15.   int row, col, count = 0;
  16.   double r = (strcmp(argv[1], "-r") == 0) ? strtof(argv[2], NULL) : strtof(argv[4], NULL);
  17.   double t = (strcmp(argv[1], "-t") == 0) ? strtof(argv[2], NULL) : strtof(argv[4], NULL);
  18.   scanf("%d", &row);
  19.   scanf("%d", &col);
  20.   double **rows = (double **)malloc(row * sizeof(double *));
  21.   for (int i = 0; i < row; i++)
  22.   {
  23.     rows[i] = (double *)malloc(sizeof(double) * col);
  24.   }
  25.  
  26.   for (int i = 0; i < row; i++)
  27.   {
  28.     for (int j = 0; j < col; j++)
  29.     {
  30.       scanf("%lf", &rows[i][j]);
  31.     }
  32.   }
  33.   for (int i = 0; i < row; i++)
  34.   {
  35.     for (int j = 0; j < col; j++)
  36.     {
  37.       if (approxEqual(rows[i][j], r, t))
  38.       {
  39.         count++;
  40.         fprintf(stdout, "r=%d, c=%d: %.6f\n", i, j, rows[i][j]);
  41.       }
  42.     }
  43.   }
  44.   fprintf(stdout, "Found %d approximate matches.\n", count);
  45.   time(&end);
  46.   local = localtime(&end);
  47.   printf("# End time and date: %s", asctime(local));
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement