Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Programming

FORUM Dedicated to Programming
 
HomePortalLatest imagesSearchRegisterLog in

 

 help in loop

Go down 
2 posters
AuthorMessage
coolfaisal89
Level 0
Level 0



Number of posts : 1
Registration date : 2008-11-23

help in loop Empty
PostSubject: help in loop   help in loop I_icon_minitime23/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
Back to top Go down
ammar26
Administrator
Administrator



Number of posts : 18
Age : 34
Registration date : 2008-11-12

help in loop Empty
PostSubject: Hmmm .... Answer   help in loop I_icon_minitime23/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
Back to top Go down
http://www.softxtreme.com
 
help in loop
Back to top 
Page 1 of 1
 Similar topics
-
» Loop practice questions in C and C++

Permissions in this forum:You cannot reply to topics in this forum
Programming :: C & C++ Programming :: C & C++ Discussions & Solutions-
Jump to: