Problem Statement - Secret code with alphabet divisible by five
Instead of sending his secret code a programmer tells his friend that my secret code is a series of characters which are upper and lower alphabet sequence in their ascending order which are divisible by five. Can you help the programmer’s friend to decipher this code.
Solution
Run Output
Solved Problem Understanding
for(int i=65;i<=90;i++)
This one takes care of upper case range of alphabets from 65 to 90
if(i%5==0) cout<<(char)i<<” “;
Here we check divisibility by 5 using i%5==0. If divisible we print the equivalent alphabet by (char) typecasting of equivalent integer ascii code.
for(int i=97;i<=122;i++)
This one is for lower case alphabet range from 97 to 122.
if(i%5==0) cout<<(char)i<<” “;
Here again divisibility by 5 is tested and then character version is printed.
Finally we get the code as
A F K P U Z d i n s x
Notes
- These are innovative ways of narrating simple programming assignments. students are advised to carefully mark each of the relevant words in the question like follows -“Instead of sending his secret code a programmer tells his friend that my secret code is a series of characters which are upper and lower alphabet sequence in their ascending order which are divisible by five. Can you help the programmer’s friend to decipher this code.”
