HCL Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




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

Here is my solution using macros.

#include <stdio.h>

#define concantenateNumbers(A,B) B##A

int main()
{
    int i;
    i = concantenateNumbers(12,36);
    printf("%d\n", i);
    return 0;
}

- goldentss July 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is the point of this question to be asked in interviews?

- Sandeep Chauhan December 29, 2015 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

in my view the result can be obtained by (36*100)+12=3612.
But since arithmetic operation are not allowed so we first break 100 into sum of power of 2s
i.e. 100=(64+32+4)
Now, 36 can be multiplied by 64,32 and 4 using bit operators such as
let d1=36<<6;
d2=36<<5
d3=36<<2;
now d1, d2 d3 can be added again using bitwise operator using concept of half adder
Since finally we will get a=3600;
again using half adder concept we can easily add 12 to it
and hence obtain 3612.

halfadder(int a,int b)
{
a=a^b;
if((a&b)==0)
{
break;
}
b=a&b;
b=b<<1;
}

- Ankit Mittal June 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Sorry, my halfadder logic is little wrong;
int Add(int x, int y)
{
// Iterate till there is no carry
while (y != 0)
{
// carry now contains common set bits of x and y
int carry = x & y;

// Sum of bits of x and y where at least one of the bits is not set
x = x ^ y;

// Carry is shifted by one so that adding it to x gives the required sum
y = carry << 1;
}
return x;
}

// sorry for the mistake . Actually this is my 1st attempt for an answer . I hope no one minds it

- Ankit Mittal June 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ideone.com/TeCXfC add http to this. This is with your solution.

- aka[1] June 30, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what do you mean by not using arithmetic? Which arithmetic operators are allowed?

- aka[1] June 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <sstream>

using namespace std;

int main () {
stringstream ss;
int a=12, b=36;

ss << b;
ss << a;

cout << ss.str() << endl;
return 0;
}

- Anonymous August 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main() {
int a=12, b=36;
printf("%d%d",b,d);
return0;
}

- SPANDANA JUKANTI September 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 #include<stdio.h>
  2 
  3 int main(int argc, char *argv[])
  4 {
  5         int a = 12, b = 36;
  6         printf("%d%d\n", a, b);
  7 
  8         return 0;
  9 }

- AlgarveBeachBum January 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 #include<stdio.h>
3 main()
4 {
5 int a = 12, b = 36;
6 printf("c=%d%d\n", b,c);
}

- Anonymous September 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Here is the algorithm.

1. First find the number of digits in first operand 'a' ( this is equal to the power of 10)
2. We need to multiply this power of 10 with the second operand 'b'.
3. Then OR (|) result from step 2 and the first operand 'a'.

public class Concatenate {
	
	public static void main(String[] args) {
		
		int a = 12;
		int b = 36;
		
		int digit_count = (int) Math.log10(a)+1; // To find the number of digits in first operand
		
		int c = 0;
		switch(digit_count){
		
			case 1 :	// Power of 10 is 1.
					c = (b << 3) + (b << 1);	// 10^1(10) = 2^3(8)+ 2^1(2)
					break;
		
			case 2 :	// Power of 10 is 2.
					c = (b << 6) + (b << 5)+ (b << 2); // 10^2(100) = 2^6(64)+ 2^5(32)+ 2^2(4)
					break;
		}
		
		c = c | a; // Add the both the values to get the output.
		
		System.out.println(c); // Outputs 3612
	}
}

- ram.prasad.prabu June 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Arithmatic operator is used to add while processing.

- soni.komal712 August 06, 2015 | Flag


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