11879 - Multiple of 17
Problem Link: https://uva.onlinejudge.org/external/118/11879.pdf
Algorithm: This problem is quite easy. In this, there will be a number which is greater at most 100 digits. So, Its not possible to store it in “long long int” in c++.
We will write a program which will take input a string. If the string contains only 0 then the program will be break, otherwise it will enter in another loop. Before entering I will declare two integer variables ‘reminder’ and ‘i’. I will initialize the reminder variable to 0;
1 | char s[110]; |
Then there will be loop which will start from the beginning of string to the end. It will be look like-
1 | for(i=0;s[i]!='\0';i++){ |
Now I will multiply the reminder by 10 and sum it with the current digit of the string(due to string case you need to subtract 48 from the current character and it will be count as digit in integer). again I will find the reminder of the previous reminder diving by 17 and will store it in reminder variable. This process continues until the loop ends.
1 | reminder=reminder\*10+(s[i]-48); |
After the loop ends my program will check whether the reminder variable is zero or not. If it is zero that means the big number(string) is multiple of 17 else it not.
if it is multiple of 17 then my program will print 1 , if this is not multiple of 17 then the program will print 0.
1 | if(reminder==0) |
Now all the steps are done. Now lets combine all the codes in one place.
1 | //Problem Link: https://uva.onlinejudge.org/external/118/11879.pdf |
WhatsUP