Programming

FORUM Dedicated to Programming
 
HomePortalCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 help in loop

View previous topic View next topic Go down 
AuthorMessage
coolfaisal89
Level 0
Level 0


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

PostSubject: 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
Back to top Go down
View user profile
ammar26
Administrator
Administrator


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

PostSubject: 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
Back to top Go down
View user profile http://www.softxtreme.com
 
help in loop
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» How Click on Dynamic Objects at Dynamic Positions in Selenium using for loop
» [SOLVED] Windows 10 TP 10041 installation Error *loop*
» Loop Recorder Implant
» Can I check the error message displayed or not in Selenium?
» how to use while statement in ide

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