【发布时间】:2011-12-11 10:34:37
【问题描述】:
#include <stdio.h>
void caesar (char cipher[], int shift);
int main () {
char cipher[50];
int shift;
printf("Enter text to be encrypted IN CAPITAL LETTERS ONLY: ");
scanf("%s", cipher);
printf("How many shifts do you prefer? 1-10 only: ");
scanf("%d", &shift);
caesar (cipher, shift);
return 0;
}
void caesar (char cipher[], int shift) {
int i = 0;
while (cipher[i] != '\0') {
if ((cipher[i] += shift) >= 65 && (cipher[i] += shift) <= 90) {
cipher[i] += (shift);
} else {
cipher[i] += (shift - 25);
}
i++;
}
printf("%s", cipher);
}
我开始获得加密输出,但我担心我的陈述有问题。
例如:
- 输入:ABCD,1 班
- 输出:DEFG
【问题讨论】: