Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- using namespace std;
- int main()
- {
- FILE *fl;
- int x;
- int n;
- if ((fl = fopen("nechetnie", "wr")) == NULL) {
- cout << "Error creating the file";
- return 0;
- }
- cout << "Enter your numbers: ";
- for (n = 0; n < 10; n++) {
- cin >> x;
- fwrite(&x, sizeof(int), 1, fl);
- }
- fclose(fl);
- if ((fl = fopen("nechetnie", "rb")) == NULL) {
- cout << "Error opening the file";
- return 0;
- }
- int a, b;
- int nech = 0;
- fread(&a, sizeof(int), 1, fl);
- for (n = 0; n < 10; n++) {
- fread(&b, sizeof(int), 1, fl);
- if (a % 2 != 0 && b > 0) {
- nech++;
- }
- a = b;
- }
- cout << "Kolichestvo chisel: " << nech << endl;
- fclose(fl);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement