-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.CPP
66 lines (65 loc) · 1.22 KB
/
20.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using namespace std;
#include <conio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
int main()
{
ofstream f1, f2, f3;
ifstream fi1, fi2, fi3;
int i, n, x;
f1.open("data.txt");
cout << "\n Enter no.of elements you have:";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "\n Enter elements" << i << ":";
cin >> x;
f1 << x << " ";
}
f1.close();
fi1.open("data.txt");
f3.open("even.txt");
f2.open("odd.txt");
for (i = 1; i <= n; i++)
{
fi1 >> x;
if (x % 2 == 0)
{
f3 << x << " ";
}
else
{
f2 << x << " ";
}
}
f3.close();
f2.close();
fi1.close();
fi1.open("data.txt");
fi2.open("odd.txt");
fi3.open("even.txt");
cout << "\ncontent of data file:\n";
while (fi1)
{
fi1 >> x;
cout << x << "\t";
}
fi1.close();
cout << "\n Content of odd file:\n";
while (fi2)
{
fi2 >> x;
cout << x << "\t";
}
fi2.close();
cout << "\ncontent of even file:\n";
while (fi3)
{
fi3 >> x;
cout << x << "\t";
}
fi3.close();
cout << "\n Compelte.....";
return 0;
}