1003: C语言程序设计教程(第三版)课后习题3.7

来源:互联网 发布:2000坐标系数据转换 编辑:程序博客网 时间:2024/05/16 17:00

题目描述
要将”China”译成密码,译码规律是:用原来字母后面的第4个字母代替原来的字母.例如,字母”A”后面第4个字母是”E”.”E”代替”A”。因此,”China”应译为”Glmre”。请编一程序,用赋初值的方法使cl、c2、c3、c4、c5五个变量的值分别为,’C’、’h’、’i’、’n’、’a’,经过运算,使c1、c2、c3、c4、c5分别变为’G’、’l’、’m’、’r’、’e’,并输出。

输入
China

输出
加密后的China

样例输入
China
样例输出
Glmre

#include<stdio.h>int main(){    char a, b, c, d, e;    scanf("%c%c%c%c%c", &a, &b, &c, &d, &e);    printf("%c%c%c%c%c\n", a+4, b+4, c+4, d+4, e+4);    return 0;}
#include<stdio.h>#define N 5int main(){    char str[N];    scanf("%s", str);    int i = 0;    for(; i<N; i++){        printf("%c", str[i]+4);    }    printf("\n");    return 0;}

这里写图片描述

0 0