fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <ctype.h>
  5.  
  6. int main(void) {
  7. const char *article[] = {"the", "a", "one", "some", "any"};
  8. const char *noun[] = {"boy", "girl", "dog", "town", "car"};
  9. const char *verb[] = {"drove", "jumped", "ran", "walked", "skipped"};
  10. const char *prep[] = {"to", "from", "over", "under", "on"};
  11.  
  12. srand(time(NULL));
  13.  
  14. printf("Random Limerick:\n");
  15. for (int i = 0; i < 5; i++) {
  16. char line[100];
  17. sprintf(line, "%s %s %s %s %s %s",
  18. article[rand() % 5], noun[rand() % 5],
  19. verb[rand() % 5], prep[rand() % 5],
  20. article[rand() % 5], noun[rand() % 5]);
  21. line[0] = toupper(line[0]);
  22. printf("%s%s\n", line, (i == 4) ? "." : ",");
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 5332KB
stdin
Standard input is empty
stdout
Random Limerick:
One dog walked under one boy,
A dog walked on a car,
One car drove on any girl,
One girl walked over the boy,
Any car walked over some dog.