Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@srinivas-j-XNEHhO • Jan 9, 2011
hi!! dude the following code serves your purpose!!
#include<stdio.h>
void main()
{
float a,b,r=0;
printf("\n\n\tEnter Values of a & b :");
scanf("%d%d",&a,&b);
while(b*r <= a)
r++;
printf("\n\n\tAnswer is : %d ",r-1);
}
Have a Nice time!!(Note : It's for Integers!! ie, i've not taken floating point division to easy the task!!) -
@sachin-0wuUmc • Jan 9, 2011
Thats OK...Actually its a YAHOO interview question.
I thought of doing like this :-
We have to calculate y=A/B
So take log of both sides
log y=log(A/B)
log y=log A - log B
calculate log A - log B=x say
Then take antilog both sides
y=antilog (x)
In this way we can find A/b without using / and % operator.
Thats what i thought -
@silverscorpion-iJKtdQ • Jan 9, 2011
Here, I think the printf statement should be outside the while loop!! 😀srinivas_jhi!! dude the following code serves your purpose!!
#include<stdio.h>
void main()
{
float a,b,r=0;
printf("\n\n\tEnter Values of a & b :");
scanf("%d%d",&a,&b);
while(b*r <= a)
r++;
printf("\n\n\tAnswer is : %d ",r-1);
}
Have a Nice time!!(Note : It's for Integers!! ie, i've not taken floating point division to easy the task!!) -
@srinivas-j-XNEHhO • Jan 11, 2011
no!! it's not inside d while loop!! it's outside itself try it out by Executing!! -
@prabait28-OKNXt2 • Jan 12, 2011
Tell me Any other crct answer with simple concept..... -
@srinivas-j-XNEHhO • Jan 13, 2011
it's d simplest one & it takes very less cpu cycle time compared to ur other method!! & mor over logic is simple!