#include<iostream>
#include<fstream>
using namespace std;
int main(){
int arr[10] = {90,100,200,400,40,60,80,30,60,70};
ofstream file("DATA.txt", ios::out);
for(int i=0; i<10; i++){
file<<arr[i]<<endl; //Writing the set of integers to the file
}
file.close();
ifstream file1("DATA.txt", ios::in);
int arr1[10];
for(int i=0; i<10; i++){
file1>>arr1[i]; //Putting the content of the file in the array
}
for(int i=0; i<10; i++){
cout<<"The element1 is\t"<<arr1[i]<<endl;
}
file1.close();
int given_element = 400; //400 is the given element but any element can be searched
ofstream file2("FACTORS.txt", ios::out);
for(int i=1 ;i<10; i++){
if(arr1[i] == given_element){
for(i=0; i<given_element; i++){
if(given_element % i == 0){
file2<<i<<"\n";
}
}
}
}
file2.close();
ifstream file3("FACTORS.txt", ios::in);
int arr2[10];
for(int i=0; i<10; i++){
file3>>arr2[i]; //Writing the set of integers to the file
}
file3.close();
for(int i=0; i<10; i++){
cout<<"The element is\n"<<arr2[i]<<endl;
}
}
Comments
Leave a comment