0
I have studied C and came across a very difficult problem that after a lot of trying, I gave up and went to look for an algorithm ready on the internet to study on it, but the expression n %= 100 I could not understand at all. I searched several programming and math sites but all I could find was that the percentage symbol in the middle of two whole numbers returned the rest of the division, and this I already knew, but when there’s an equality together?
If it helps the problem is the 1018 of the URI beginner module.
Here’s the code I’m studying:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", n);
printf("%d nota(s) de R$ 100,00\n", n/100);
n %= 100;
printf("%d nota(s) de R$ 50,00\n", n/50);
n %= 50;
printf("%d nota(s) de R$ 20,00\n", n/20);
n %= 20;
printf("%d nota(s) de R$ 10,00\n", n/10);
n %= 10;
printf("%d nota(s) de R$ 5,00\n", n/5);
n %= 5;
printf("%d nota(s) de R$ 2,00\n", n/2);
n %= 2;
printf("%d nota(s) de R$ 1,00\n", n);
return 0;
}
Do you understand that
n % 100
is the rest of then
for 100?– Jefferson Quesado