forked from sandeshghanta/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivide.cpp
More file actions
37 lines (37 loc) · 763 Bytes
/
divide.cpp
File metadata and controls
37 lines (37 loc) · 763 Bytes
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
#include<bits/stdc++.h>
using namespace std;
void divide(string num,int div){
int temp=0;
string quot = "";
for (int i=0;i<num.size();){
if (temp < div){
if (quot != ""){ //to avoid leading zeroes
quot = quot + '0';
}
temp = temp*10 + (num[i]-48);
i++;
}
else{
quot = quot + (char)((temp/div)+48);
temp = temp%div;
temp = temp*10 + (num[i]-48);
i++;
}
}
if (temp >= div){
quot = quot + (char)((temp/div)+48);
temp = temp%div;
}
cout << "quotient is " << quot << endl;
cout << "remainder is " << temp << endl;
}
int main(){
string num;
int div;
cout << "Enter a big number " << endl;
cin >> num;
cout << "Enter a number " << endl;
cin >> div;
divide(num,div);
return 0;
}