coolfaisal89 Level 0
Number of posts : 1 Registration date : 2008-11-23
| Subject: help in loop 23/11/08, 04:49 pm | |
| i want to take two integers as input and divide them without using division operator. i know it is done by repeated subtraction but i am only able to get answer in whole numbers i want to get answer in decimal points e.g. 11/2 shall give 2.75 but without division operator | |
|
ammar26 Administrator
Number of posts : 18 Age : 34 Registration date : 2008-11-12
| Subject: Hmmm .... Answer 23/11/08, 06:21 pm | |
| Faisal you can perform it with out loop , if you use pow(); function Solution With out Loop
For C++ - Code:
-
#include<iostream> #include<cmath>
using namespace std;
int main() { int a,b; cout<<" Please Enter 2 integers"<<endl; cin>>a>>b; cout<< static_cast<double>(a) * pow(static_cast<double>(b),-1); return 0;
}
For decimal point u can use setpricision(n); now | |
|