Hewlett Packard Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

For * operation

We can add the first number, second number of times.
Say i=4, j=5;

//Run a for loop for 5 times(j), add i in each //cycle.
for j->0 to 4
add sum += i;

For - operation.

//Brute force approach
Increment the smaller number and keep a count till it reaches the larger number

For / operation.
follow the method given above for * operation, and keep a count every time you add. That count would be the Quotient.

I hope this answer suffice. Plz correct me if i'm wrong

- Niti December 05, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well what will be the case if we have to say multiply 4 & -7
well you are near it but it needs to be improved

- Abhishek Anand September 19, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just check signs for * and /...
(+,-) -> -
(-,-) -> + and so on...
In (a - b), check if a > b or b > a,
if a > b then increment b else put a - sign and increment a !
also check for special conditions like a = b, or division by zero, etc

- Ankit Gupta August 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we must overload + operator.

- Srivatsa December 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

think this shud be d answer interviewer wud ve expected

- Anonymous August 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void ProcessMenu(void)
{
	printf("\nCalc with +  *: %i", CalcWithOnlyAdd('*', 10, 2));
	printf("\nCalc with +  -: %i", CalcWithOnlyAdd('-', 4, 8));
	printf("\nCalc with +  /: %i", CalcWithOnlyAdd('/', 10, 3));
}

int CalcWithOnlyAdd( char Operator, int Num1, int Num2)
{
	int Result = 0;
	int I, J;

	switch (Operator)
	{
	case '*':
		Result = 0;
		for (I = 0; I < Num2; I++)
		{
			Result = Result + Num1;
		}
		break;
	case '-':
		Result = Num1;
		for (I = 0; I < Num2; I++)
		{
			Result = Result + (0xffffffff);
		}		
		break;
	case '/':
		Result = Num1;
		J = 0;
		while (Result >= Num2)
		{
			for (I = 0; I < Num2; I++)
			{
				Result = Result + (0xffffffff);
			}
			J++;
		}
		Result = J;
		break;
	}

	return(Result);
}

- KKC March 17, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More