fork download
  1. #include <stdio.h>
  2.  
  3. char caesar(char c, int n) {
  4. if (c >= 'A' && c <= 'Z') {
  5. return 'A' + ( (c - 'A' + n + 26) % 26 );
  6. } else if (c >= 'a' && c <= 'z') {
  7. return 'a' + ( (c - 'a' + n + 26) % 26 );
  8. } else {
  9. return c;
  10. }
  11. }
  12.  
  13. int main() {
  14. char c;
  15. int shift;
  16.  
  17. printf("文字を1つ入力してください: ");
  18. scanf(" %c", &c);
  19.  
  20. printf("シフト量を入力してください: ");
  21. scanf("%d", &shift);
  22.  
  23. char result = caesar(c, shift);
  24. printf("変換結果: %c\n", result);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 5276KB
stdin
A
3
stdout
文字を1つ入力してください: シフト量を入力してください: 変換結果: D