Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. int rot13(int);
  5. bool is_lowcase(int);
  6. bool is_upcase(int);
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. int b, r;
  11. printf("Enter a number to see its rot13: ");
  12. scanf("%c", &b);
  13. r = (char)rot13(b);
  14. printf("The rot13 of %c is %c.\n", b, r);
  15.  
  16. return 0;
  17. }
  18.  
  19. int rot13(int c)
  20. {
  21. int k;
  22. if (is_upcase(c)) {
  23. if (c > 'M') {
  24. c -= 13;
  25. }
  26. else {
  27. c += 13;
  28. }
  29. }
  30. else if (is_lowcase(c)) {
  31. if (c > 'm') {
  32. c -= 13;
  33. }
  34. else {
  35. c += 13;
  36. }
  37. }
  38. else {
  39. return c;
  40. }
  41. }
  42.  
  43. bool is_lowcase(int c)
  44. {
  45. if (c >= 'a' && c <= 'z') {
  46. return true;
  47. }
  48. else {
  49. return false;
  50. }
  51. }
  52.  
  53. bool is_upcase(int c)
  54. {
  55. if (c >= 'A' && c <= 'Z') {
  56. return true;
  57. }
  58. else {
  59. return false;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement