fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <ctype.h>
  4.  
  5. int main() {
  6. bool composite[1100] = {true, false, false};
  7. char L[100];
  8. int total;
  9.  
  10. // Pre-calculate prime sieve
  11. for (int i = 2; i < 1100; i++) {
  12. if (!composite[i]) {
  13. for (int j = i + i; j < 1100; j += i) {
  14. composite[j] = true;
  15. }
  16. }
  17. }
  18.  
  19. while (fgets(L, sizeof(L), stdin) != NULL) { // Read line with fgets
  20. total = 0;
  21. for (int i = 0; L[i] != '\0'; i++) { // Loop until null terminator
  22. if (isupper(L[i])) {
  23. total += L[i] - 'A' + 27;
  24. } else if (islower(L[i])) {
  25. total += L[i] - 'a' + 1;
  26. }
  27. }
  28.  
  29. printf("It is %s a prime word.\n", composite[total] ? "not" : ""); // Conditional string printing
  30. }
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5280KB
stdin
8
stdout
It is not a prime word.