Created
July 14, 2019 08:46
-
-
Save umair313/a4f12cd0bf3ac7648044d2ec198cf08c to your computer and use it in GitHub Desktop.
program perform division with out division operator and display result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int numerator=679; | |
int denominator=3; | |
int count=0; | |
int flag=0; | |
int numerator_high=0; | |
if(numerator>denominator){ | |
numerator_high=1; | |
while(denominator<numerator){ | |
while(count* denominator <= numerator){ | |
flag=1; | |
count++; | |
} | |
count--; | |
numerator=numerator-(count*denominator); | |
cout<<count; | |
if(flag!=1) | |
break; | |
else | |
count=0; | |
flag=0; | |
} | |
} | |
if(numerator!=0){ | |
if(numerator_high==0) | |
cout<<0; | |
if(numerator<denominator){ | |
cout<<"."; | |
while(numerator<denominator){ | |
numerator*=10; | |
} | |
///// | |
while(denominator<numerator){ | |
while(count* denominator <= numerator){ | |
flag=1; | |
count++; | |
} | |
count--; | |
numerator=numerator-(count*denominator); | |
cout<<count; | |
if(flag!=1) | |
break; | |
else | |
count=0; | |
flag=0; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment