Guest User

Untitled

a guest
Jan 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. int
  7. main(int argc, char *argv[])
  8. {
  9. if (argc != 1)
  10. return 1;
  11.  
  12. int k = atoi(argv[1]);
  13. string phrase = GetString();
  14. int length = strlen(phrase);
  15.  
  16. for (int i = 0, n = length; i < n; i++)
  17. {
  18. if (phrase[i] >= 65 && phrase[i] <= 90)
  19. phrase[i] = ((phrase[i] + k) - 65) % 26 + 65;
  20. else if (phrase [i] >= 97 && phrase[i] <= 122)
  21. phrase[i] = ((phrase[i] + k) - 97) % 26 + 97;
  22. else
  23. phrase[i] = phrase [i];
  24. printf("%c", phrase[i]);
  25. }
  26.  
  27. printf("\n");
  28.  
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment