-1
void main()
{

    int  u, t, h ;

    printf("\n Enter a number (with 3 digits) \n");

    printf("\n Enter the unit digit number \n");

    scanf("%d",&u);

    printf("\n Enter the tenth digit number \n");

    scanf("%d",&t);

    printf("\n Enter the hundredth digit number \n");

    scanf("%d",&h);

}

I want them in order like if user input u as 1, t as 2 and h as 3, then after concatenation it should print 321 together as one integer number.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Mehul Chachada
  • 563
  • 9
  • 24
  • Note the discussion in [What should `main()` return in C and C++](http://stackoverflow.com/questions/204476/c/18721336#18721336). You should be checking each of the inputs — ensuring that the `scanf()` returned a value, and also checking that the value entered was in the range 0..9 as values outside that range (negative numbers, or numbers in the tens, hundreds, thousands, millions or billions will throw any calculation off). OTOH, you may still be learning the basics and such niceties are out of scope as yet. If so, remember that this is toy code, needing a lot of improvement. – Jonathan Leffler Aug 23 '15 at 20:44

3 Answers3

2

With this solution the final string stored in str is portable throughout your program.

char str[16];
sprintf(str, "%d", (h*100) + (t*10) + u);
printf("%s\n", str);
asdf
  • 2,927
  • 2
  • 21
  • 42
2

Why not simply multiply them?

printf( "%d\n", 100 * h + 10 * t + u ); 

Take into account that as only one digit is read for each number you could write for example

scanf( "%1d", &u );
         ^^
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

Doesn't this work?

printf("%d%d%d", h,t,u);
CrookedBadge
  • 130
  • 9
  • This would work in that it would produce the required 321 output (unless the prescription "should print 321 together as one integer number" precludes it). It isn't clear what @MehulChachada's problem was. – Jonathan Leffler Aug 23 '15 at 20:47