I graduated in 1990 in Electrical Engineering and since then I have been in university, doing research in the field of DSP. To me programming is more a tool than a job.
withAda.Strings.Unbounded;useAda.Strings.Unbounded;subtypeParameter_TypeisIntegerrange10..9999;subtypeFruit_IndexisIntegerrange1..100;Names:array(Fruit_Index)ofUnbounded_String:=(-- Fill with names);functionSubctractSum(N:Parameter_Type)returnUnbounded_Stringis(ifNinFruit_IndexthenNames(N)else"apple");-- Explanation: -- N can be written as ---- N = a*1000 + b*100 + c*10 + d ---- if N <= 100, we access directly the name array. ---- If N > 100 (which means b >= 1) the new N is---- New_N = a*1000 + b*100 + c*10 + d - (a+b+c+d)-- = a*999 + b*99 + c*9---- If the iteration stops with New_N it must be -- New_N <= 100 which implies a = 0, b=1 -- (it cannot be b=0 otherwise we would had -- not done another iteration) and c=0, that is, -- New_N = 99.---- Therefore, unless N<=100, the result is "apple"
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ada solution