Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "utils.c"
- #include <sys/time.h>
- int main(int argc, char *argv[])
- {
- struct timeval tim;
- gettimeofday(&tim, NULL);
- double t1 = tim.tv_sec + (tim.tv_usec / 1000000.0);
- int row, col, count = 0;
- int printVals = 0;
- double r, t;
- for (int i = 0; i < argc - 1; i++)
- {
- if (strcmp(argv[i], "-r") == 0)
- {
- r = strtof(argv[i + 1], NULL);
- }
- else if (strcmp(argv[i], "-t") == 0)
- {
- t = strtof(argv[i + 1], NULL);
- }
- else if (strcmp(argv[i], "-v") == 0)
- {
- printVals = 1;
- }
- }
- scanf("%d", &row);
- scanf("%d", &col);
- double **rows = (double **)malloc(row * sizeof(double *));
- for (int i = 0; i < row; i++)
- {
- rows[i] = (double *)malloc(sizeof(double) * col);
- }
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < col; j++)
- {
- scanf("%lf", &rows[i][j]);
- }
- }
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < col; j++)
- {
- if (approxEqual(rows[i][j], r, t))
- {
- count++;
- if (printVals == 1)
- {
- fprintf(stdout, "r=%d, c=%d: %.6f\n", i, j, rows[i][j]);
- }
- }
- }
- }
- fprintf(stdout, "Found %d approximate matches.\n", count);
- gettimeofday(&tim, NULL);
- double t2 = tim.tv_sec + (tim.tv_usec / 1000000.0);
- printf("%.6lf seconds elapsed\n", t2 - t1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement