Elegant piece of code!! I really appreciate the way u join the two functions. And yes stdlib really didn't mean to be there. I just skipped the non-essential include part and concentrated on the part where zhshqzyc might be erring. But on the combining of the two functions I would like to make a small comment though ur code does what is expected of the code but this might not be the real intension of the programmer, may be he was presenting it in most simple way. Although here the calls to get input and display results are sequential but in real problem he might be facing he may be calling input once and printing the elements twice or thrice so it doesn't make sense to combine two functions with two different functionality.
Further I quote
Quote:
your code can be further optimised to have a common function as below instead of having two seperate functions
I really couldn't figure it out how this tweak of urs ensured code optimization.
The calls are two separate calls and overhead of switching from main to ur function is also incurred twice (as it might have been, had there been two functions as before) rather I feel that ur induction of a global variable 'glb' makes the code more inefficient for most modern C compilers alias local variables to CPUs register's or SRAM but can't do so with global variables. Furthermore, if all variables in a given scope are local, then an optimizing compiler, can forgo maintaining the variable outside the scope, and therefore has more simplification optimization opportunities than with global.
Add to it the time in evaluation of logical operators.
The only way I feel ur code can be made really efficient might be by declaring the function static making the call a fixed function call.
Please rectify me if I've gone wrong somewhere.