Hey! If you are a beginner in the vast world of programming, then you are at the right place. In this CodeChef tutorial blog, we will be solving the “Find Remainder” problem. Before we jump into the explanation, I will give you a quick overview of the question.
In this problem, you first enter the number of test cases. For the time being, let us denote it using the letter ‘T’. After inputting the number of test cases, you enter the numbers, and the output will be the remainder after performing the division operation. Let us look into the logic and understand what we need to know before we solve this.
Solution in Python
Before you start reading the solution, if you have any doubts regarding the functions like input, split, and ‘for loop, then check out this blog. Now let us understand what a modulo function does. The modulo operator is denoted by ‘%’. This operator returns the remainder after performing the division on the numbers. Well, now that you know what a modulo operator does, let us understand the logic.
- The first input variable is the test case. The inputted number is stored in any variable, in this instance, ‘T’.
- The next input, i.e., the numbers you want to divide, is inputted using a ‘for’ loop. The range for this loop is the integer stored in the test case variable.
- Using the split function, the numbers are separated using a specified separator.
- The print function is used to display the remainder of the numbers using the modulo operator.
Solution in C
The same logic applies here as well. But the only difference is how the input and output function is named. Instead of using the function input(), here, scanf() is used. While you input the number, you also have to use a specifier as well. In this case, since it’s a decimal integer, we use the ‘% d’ specifier. The remainder will be outputted using the printf() function.
Now it’s time for you to start practicing!