C语言,将第i个字母编程第(26-i+1)个字母,非字母字符不变。程序无法输出,求解。
#include<stdio.h>intmain(){inti=0;chara[80],b[80];printf("inputciphercode:");while((a...
#include<stdio.h>
int main()
{
int i=0;
char a[80],b[80];
printf("input cipher code:");
while((a[i]=getchar())!='\0');
{
if(a[i]>='a' && a[i]<='z') b[i]=219-a[i];
else if(a[i]>='A' && a[i]<='Z') b[i]=155-a[i];
else b[i]=a[i];
i++;
}
printf("%d %c\n",a[0],a[0]);
printf("cipher code:");
for(i=0;i!='\0';i++) printf("%c ",a[i]);
printf("\noriginal text:");
for(i=0;i!='\0';i++) printf("%c ",b[i]);
return 0;
} 展开
int main()
{
int i=0;
char a[80],b[80];
printf("input cipher code:");
while((a[i]=getchar())!='\0');
{
if(a[i]>='a' && a[i]<='z') b[i]=219-a[i];
else if(a[i]>='A' && a[i]<='Z') b[i]=155-a[i];
else b[i]=a[i];
i++;
}
printf("%d %c\n",a[0],a[0]);
printf("cipher code:");
for(i=0;i!='\0';i++) printf("%c ",a[i]);
printf("\noriginal text:");
for(i=0;i!='\0';i++) printf("%c ",b[i]);
return 0;
} 展开
展开全部
#include<stdio.h>
int main()
{
int i=0;
char a[80]={"\0"},b[80]={"\0"};
printf("input cipher code:");
while((a[i]=getchar())!='\n')
{
if(a[i]>='a' && a[i]<='z') b[i]=219-a[i];
else if(a[i]>='A' && a[i]<='Z') b[i]=155-a[i];
else b[i]=a[i];
i++;
}
printf("%d %c\n",a[0],a[0]);
printf("cipher code:");
for(i=0;i!='\n';i++) printf("%c ",a[i]);
printf("\noriginal text:");
for(i=0;i!='\n';i++) printf("%c ",b[i]);
return 0;
}
帮你改了一下,不晓得你为什么要输出a[0],还有帮你把结束输入的符号改为了回车(因为getchar和scanf不一样,会把回车读进来的),你再试一下
int main()
{
int i=0;
char a[80]={"\0"},b[80]={"\0"};
printf("input cipher code:");
while((a[i]=getchar())!='\n')
{
if(a[i]>='a' && a[i]<='z') b[i]=219-a[i];
else if(a[i]>='A' && a[i]<='Z') b[i]=155-a[i];
else b[i]=a[i];
i++;
}
printf("%d %c\n",a[0],a[0]);
printf("cipher code:");
for(i=0;i!='\n';i++) printf("%c ",a[i]);
printf("\noriginal text:");
for(i=0;i!='\n';i++) printf("%c ",b[i]);
return 0;
}
帮你改了一下,不晓得你为什么要输出a[0],还有帮你把结束输入的符号改为了回车(因为getchar和scanf不一样,会把回车读进来的),你再试一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询