Buy Questpond's video subscriptions on
huge discount
.
Online: 2245
Home
Articles
Interviews
Forums
For Beginners
Popular Questions
ITIL Career Advice
PMP Career Advice
Career Advices
Codes
Videos
ASP.NET
ASP.NET MVC
Android Intel XDK
Sql Server
AngularJS
Bootstrap
Backbone.JS
MongoDB
LESS (CSS)
jQuery
WPF
WWF
SSIS
LightSwitch
Tutorials
News
ASP.NET MVC
|
Be Interview Ready
|
Top Performers
|
DNF MVP
|
Top Posts
|
Winners
|
Subscribe
|
Catalogs
Welcome Guest !
Register
Login
Home
>
Interviews
>
Others
>
Loading ...
Multiply a number without using the '*' operator.
Posted by
Dotnetrajanikanth
on 4/18/2012 | Category:
Others Interview questions
| Views: 4524 |
Points: 40
Post
|
Interview FAQs
|
Exclusive Questions
|
Interview Home
Answer:
Simplest answer that i could give is
for(i=0;i<n;i++)
{
num = num+num
}
Hope this helps...
Source:
Experience |
Asked In:
interview |
Alert Moderator
Bookmark It
< Previous :
How Many Parameters per stored procedure in Sql Se ...
Next > :
How to change a label value using javascript?
Comments or Responses
Posted by:
Dotnetrajanikanth
on: 4/19/2012 |
Points: 10
The same idea can be used to implement division also
Posted by:
dhirenkaunar-15094
on: 4/19/2012 |
Points: 10
Hi,
The above code will return wrong result
Ex : if will execute with assumtion n=2 and num=3
for(i=0;i<n;i++)
{
num = num+num
}
i=0 num=6
i=1 num=12
it will resolve if will use third variable
res=0
for(i=0;i<n;i++)
{
res+=num ;
}
i=0 res=3
i=1 , res=6
BUt the above condition will be fail if we have -ve number
Hope the below code will help.
int num = -5, i, num2 = -3;
int res=0;
int negCtr = 0;
if (num < 0)
{
num = num * -1;
negCtr++;
}
if (num2 < 0)
{
num2 = num2 * -1;
negCtr++;
}
for (i = 0; i < num2; i++)
{
res += num;
}
if (negCtr == 1)
{
res = res * -1;
}
Thanks,
Dhiren
Posted by:
Stefanstaev
on: 4/19/2012 |
Points: 10
Hope this helps...
- this is not helpfull. I am reading a lot of "spam" articles in the last months.
Posted by:
Dotnetrajanikanth
on: 4/19/2012 |
Points: 10
Thank you for pointing out the error...
Login to post response
More Interview Questions by Dotnetrajanikanth
Latest Interview Questions
How to change a label value using javascript?
How to write in browser page using javascript?
How many different ways XSS attacks can occur?
what is JsRender?
What debugging options does Netscape have?
A method is the object oriented version of
Which event tests if a form field has changed?
How a procedure can be encrypted?
More ...