Advertisement
palenda21

Lab9A

Mar 19th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <math.h>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     FILE *fl;
  13.     int x;
  14.     int n;
  15.     if ((fl = fopen("nechetnie", "wr")) == NULL) {
  16.         cout << "Error creating the file";
  17.         return 0;
  18.     }
  19.     cout << "Enter your numbers: ";
  20.     for (n = 0; n < 10; n++) {
  21.         cin >> x;
  22.         fwrite(&x, sizeof(int), 1, fl);
  23.     }
  24.     fclose(fl);
  25.     if ((fl = fopen("nechetnie", "rb")) == NULL) {
  26.         cout << "Error opening the file";
  27.         return 0;
  28.     }
  29.    
  30.     int a, b;
  31.     int nech = 0;
  32.     fread(&a, sizeof(int), 1, fl);
  33.     for (n = 0; n < 10; n++) {
  34.         fread(&b, sizeof(int), 1, fl);
  35.         if (a % 2 != 0 && b > 0) {
  36.             nech++;
  37.         }
  38.         a = b;
  39.     }
  40.     cout << "Kolichestvo chisel: " << nech << endl;
  41.     fclose(fl);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement