-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram 1.cpp
66 lines (66 loc) · 1.65 KB
/
Program 1.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
#include<iostream>
#include<fstream>
#include<sstream>
using namespace std;
int main()
{
int number[100]; // we will assume we have array with maximum number 100
int repeated[50]; //array for repeated unmbers
string line; //string to read line from file
int n; //int for convert string of integers to array integers
int i=0;
ifstream myfile("Numbers"); // get file with name Numbers with reference myfile
if(myfile.is_open())
{
while(getline(myfile,line)) // extract line from file
{
// cout<<line<<endl;
}
istringstream is (line);
while(is >> n)
{
number[i]=n;
i++;
}
int size= i--; // size of number array
int k=0,q=0;
for (int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(i==j)
{
continue;
}
if(number[i]==number[j])
{
k++;
}
}
if(k>0)
{
repeated[q]=number[i];
q++;
}
k=0;
}
int repeated_size=q--; //size of repeated unmbers
ofstream repeatedfile ("Repeated_Numers"); //make file with name repeated_numbers with reference repeatedfile
if(repeatedfile.is_open())
{
for(int i=0;i<repeated_size;i++)
{
repeatedfile<<repeated[i]<<" ";
}
}
for(int i=0;i<repeated_size;i++)
{
cout<<repeated[i]<<" ";
}
}
else
{
cout<<"Open the File, Please";
}
return 0;
}