Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/Humble-numbers/C/humble-numbers.c
Normal file
48
Task/Humble-numbers/C/humble-numbers.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
bool isHumble(int i) {
|
||||
if (i <= 1) return true;
|
||||
if (i % 2 == 0) return isHumble(i / 2);
|
||||
if (i % 3 == 0) return isHumble(i / 3);
|
||||
if (i % 5 == 0) return isHumble(i / 5);
|
||||
if (i % 7 == 0) return isHumble(i / 7);
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int limit = SHRT_MAX;
|
||||
int humble[16];
|
||||
int count = 0;
|
||||
int num = 1;
|
||||
char buffer[16];
|
||||
|
||||
memset(humble, 0, sizeof(humble));
|
||||
|
||||
for (; count < limit; num++) {
|
||||
if (isHumble(num)) {
|
||||
size_t len;
|
||||
sprintf_s(buffer, sizeof(buffer), "%d", num);
|
||||
len = strlen(buffer);
|
||||
if (len >= 16) {
|
||||
break;
|
||||
}
|
||||
humble[len]++;
|
||||
|
||||
if (count < 50) {
|
||||
printf("%d ", num);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("Of the first %d humble numbers:\n", count);
|
||||
for (num = 1; num < 10; num++) {
|
||||
printf("%5d have %d digits\n", humble[num], num);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue