
🎼Songs I listened to whilst writing🎼
- Mermaid Melody Pichi Pichi Pitch OST
- Genshin Impact OST For Mondstadt
- Bullet Heaven 2 OST : Powerful and Bright
- Fallen Blood (OblivionAXiS Remix) | Epic Battle Fantasy 4
[C Programming]Random Draw
Right, so this past Friday,
before the weekend proper,
I’d put up a poll on Twitter (X) to choose which
Genshin Impact character to draw this time.
But, as it often goes with these things,
I didn’t quite get a conclusive result.
So, in the end, I ended up having to just knock up a
C program myself to make the final decision.
💻Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h>
int main(void) { char names[4][50]; int n = 4;
printf("Please enter 4 names:\n"); for (int i = 0; i < n; i++) { printf("Name %d:\n", i + 1); fgets(names[i], sizeof(names[i]), stdin);
size_t len = strlen(names[i]); if (len > 0 && names[i][len - 1] == '\n') { names[i][len - 1] = '\0'; } }
srand((unsigned int)time(NULL));
int winner = rand() % n;
printf("\n🎉 Result of the draw! The winner is: %s 🎉\n", names[winner]);
return 0; }
|
🪔Result