Advertisement
palenda21

9A''

Mar 3rd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 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. FILE *fl;
  10. FILE *fl2;
  11.  
  12. int main()
  13. {
  14.     if ( (fl = fopen("chisla", "wb+")) == NULL)   // creating
  15.        {
  16.            cout << "File is NOT created";
  17.        }
  18.        else
  19.        {
  20.            cout << "File is created";
  21.        }
  22.        cout << endl;
  23.  
  24.     int n;
  25.     cout << "Vvedite razmer massiva" << endl;
  26.     cin >> n;
  27.    
  28.     int * mass = new int [n];
  29.     for (int i = 0; i < n; i++)
  30.     {
  31.         cout << "[" << i << "] = ";
  32.         cin >> mass[i];
  33.     }
  34.     cout << endl;
  35.    
  36.     fwrite(mass,sizeof(mass),1,fl);
  37.     fclose(fl);
  38.     if((fl = fopen("chisla", "rb+")) == NULL)
  39.     {
  40.         cout << "File is not opened!";
  41.     }
  42.    
  43.     fread(mass,sizeof(mass), 1, fl);
  44.     fclose(fl);
  45.     if ((fl = fopen("chisla" , "rb+")) == NULL)
  46.     {
  47.         cout << "File is not opened!";
  48.     }
  49.    
  50.     int x, nech = 0, pl = 0;
  51.     while (fread(&x, sizeof(int), 1, fl) == 1)
  52.     {
  53.         if ((x - 1) % 2 != 0 && x + 1 > 0)
  54.             nech++;
  55.     }
  56.     cout << "nech = " << nech;
  57.     if((fl2 = fopen("file2", "wt+")) == NULL)
  58.     {
  59.         cout << "Oshibka pri sozdanii txt!" << endl;
  60.     }
  61.    
  62.    
  63.    
  64.    
  65.    
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement