#include <bits/stdc++.h>
using namespace std;
void divide1(int x,int y,ofstream& fout){
int qotient,rem;
if(y==0){ //check condition for not dividing by zero
fout <<"We can not divide x by y\n";
}
else{
qotient=x/y; //calculate qotient
rem=x%y; //calculate remainder
fout <<"quotient : "<<qotient<<endl; //print
quotient to file
fout<<"remainder : "<<rem<<endl; //print
remainder to file
}
}
int main(){
ofstream fout; //output stream variable
fout.open("sample.txt"); //file name
divide1(8,3,fout); //function call
fout.close(); //output stream variable close
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.