Lesson 8.

This commit is contained in:
unlockable
2022-11-07 13:49:28 +08:00
parent d12429be97
commit 777e33d692
5 changed files with 124 additions and 0 deletions

29
08/Optional01.c Normal file
View File

@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdbool.h>
bool checkDigits(int chicken, int rabbit) {
bool digits[6] = {0};
int num = chicken*1000 + rabbit;
while (num > 0) {
if (num % 10 > 6 || digits[num % 10]) {
return false;
}
else {
digits[num % 10] = true;
num /= 10;
}
}
return true;
}
int main() {
int count = 50;
for (count = 50; count < 250; count++) {
if (checkDigits(count * 2, count * 4)) {
printf("There are %d chickens and rabbits. %d chicken legs, %d rabbit legs.", count, count*2, count*4);
}
}
return 0;
}