Given 3 numbers T, r and s, where r != s and r > 1 & s > 1. Print a list of numbers from 1 to T where numbers divisible by r whose decimal representation does not contain the digit r should be replaced by the number 555 and any number (int) divisible by s whose decimal representation does not contain the number s should be replaced by the number 333. Numbers for which both of the past arguments are true should be replaced by the number 444.
Input
7 2 3
Expected Output
1 2 3 555 5 444 7
Please write the answer in pseudocode
1: Create function ispresent(int a, int b) to check if b is present in a.
1.1: while loop till the number is not equal to 0
1.1.1: extract the last digit and check if it is equal to b. If yes return 1.
1.1.2: update the number by dividing it by 10
1.2: end of loop
1.3: return 0 meaning that b is not present in a.
2: Input T, r, and s. Make an array putting numbers 1 to T in it.
3: for loop i=0 to 6
3.1: if array element at i is divisible by r*s and both ispresent(array[i],r) and ispresent(array[i],s) returns 0 then array[i]=444
3.2: else if array[i] is divisible by r and ispresent(array[i],r) returns 0 then array[i] will be 555.
3.3: else if array[i] is divisible by s and ispresent(array[i],s) returns 0 then array[i] will be 333.
3.4: end loop
4: Print the array.
5: Stop
Get Answers For Free
Most questions answered within 1 hours.