Advertisement
nguyentruong98

Untitled

Dec 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. int n;
  5. int total;
  6. int array1[1000];
  7. int array2[1000];
  8. int main()
  9. {
  10.       int i, j;
  11.       int cho;
  12.       FILE *f = fopen("expreval.txt", "r");
  13.       if (f == NULL)
  14.             printf("FILE ERROR\n");
  15.       else
  16.       {
  17.             fscanf(f, "%d", &n);
  18.             for (i = 1; i <= n; i++)
  19.             {
  20.                   fscanf(f, "%d", &array1[i]);
  21.             }
  22.             for (j = 1; j < n; j++)
  23.             {
  24.                   fscanf(f, "%d", &array2[j]);
  25.             }
  26.       }
  27.       for (i = 1; i <= n; i++)
  28.             for (j = 1; j < n; j++)
  29.             {
  30.                   if (array2[j] == 2)
  31.                   {
  32.                         cho = array1[i] * array1[i + 1];
  33.                   }
  34.                   if (array2[j] == 2 && array2[j + 1] == 2)
  35.                   {
  36.                         cho = array1[i] * array1[i + 1];
  37.                         cho = cho * array1[i + 2];
  38.                   }
  39.             }
  40.       printf("%d\n", cho);
  41.       return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement