Click here to Skip to main content
15,888,269 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
1234567891011121314

example:
input 5 -> output : 5
input 11 -> output : 0
input 19 -> output : 4


how to solve this ?
thanks very much
Posted

1 solution

Create an array (say int a[]) mapping input (the index of the array item) to the output (the value of the array item).
Then, for each input i you produce the output a[i].


[update]
It is really simple (bound checking left to the reader).

C
int output(int input)
{
  static int a[] = {1,2,3,4,5,6,7,8,9,1,0,1,1,1,2,1,3,1,4};
  return a[input];
} 

[/update]
 
Share this answer
 
v2
Comments
thatraja 12-Dec-13 5:54am    
Hi, please tell me what's he trying to do? Though I took a look on those examples but 3rd case confusing. Is that about finding position of values? or something else?
CPallini 12-Dec-13 5:58am    
It is the opposite: character '4' is the 19th.
thatraja 12-Dec-13 6:02am    
Got it, thanks
CPallini 12-Dec-13 6:27am    
You are welcome.
thatraja 12-Dec-13 6:02am    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900