你的循环条件和输入、输出都有问题。红字是修改过的。
#include<stdio.h>
int main()
{
int k;
char ch;
scanf("%d",&k);
getchar();
while(scanf("%c",&ch) && ch!='\n' )
{
if('a'<=ch&&ch<='z')
ch=(ch-'a'+k)%26+'a';
if('A'<=ch&&ch<='Z')
ch=(ch-'A'+k)%26+'A';
printf("%c",ch);
}
printf("\n");
return 0;
}
#include<stdio.h>
int main()
{
int k;
char ch;
scanf("%d",&k);
getchar();
while(scanf("%c",&ch) && ch!='\n' )
{
if('a'<=ch&&ch<='z')
ch=(ch-'a'+k)%26+'a';
if('A'<=ch&&ch<='Z')
ch=(ch-'A'+k)%26+'A';
printf("%c",ch);
}
printf("\n");
return 0;
}