Pages

Friday, July 5, 2013

Division using subtraction C++

/*
QUESTION:
WRITE A CODE for dividing two numbers but you can't use divide operator only operator that can be used for division in this question is subtraction operator i.e ' - ' 


CODE:
*/

#include <iostream>
using namespace std;
int main(){
 cout<<"\n\nEnter dividend: ";
 int a;
 cin>>a;
 cout<<"\n\nEnter divisor: ";
 int b;
 cin>>b;
 int quotient = 0;

 while(a>=b){
  a -= b;
  quotient ++;
 }

 cout<<"\nQuotient after division is: "<<quotient<<endl<<endl;

 return 0;
}

No comments:

Post a Comment