top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

C: Given two numbers a=20 b =30 write a method that return an int c=3020 without using arithmetic and string operations?

+3 votes

It was asked today in interview but could not crack it, any help.

posted Aug 13, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

3 Answers

+1 vote

Its concat i.e. b followed by a. Just need to do some trick

#include <stdio.h>

#define myfunc(a,c) b##a

int main()
    int c;
    c = myfunc(20,30);
    printf("%d\n", c);
    return 0;
answer Aug 13, 2015 by Upma
0 votes
#include <stdio.h>

int main(void) {
    int a, b;
    return 0;


answer Aug 14, 2015 by Vikram Singh
0 votes

I think there is no other way except string concatenation and arithmetic operation for your problem.
I would give you simple arithmetic logic

int a=20;
int b=30;
int c=(b*100)+a;

if you tell your purpose i would give a better solution
thank you.

answer Aug 16, 2015 by Vivek B
Question was saying no arithmetic operation :) so no + - * /
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.