1302 - C语言程序设计教程(第三版)课后习题3.7
时间限制 : 1 秒
内存限制 : 64 MB
要将"China"译成密码,译码规律是:用原来字母后面的第4个字母代替原来的字母.例如,字母"A"后面第4个字母是"E"."E"代替"A"。请编一程序,用赋初值的方法使cl、c2、c3、c4、c5五个变量的值分别为,'C’、'h’、'i’、'n’、'a’,经过运算,输出变换后的密码。
题目输入
题目输出
加密后的China
输入/输出样例
输入格式
no input needed
输出格式
Glmre
C语言解答
#include <stdio.h> main() { char c1='C',c2='h',c3='i',c4='n',c5='a'; c1+=4; c2+=4; c3+=4; c4+=4; c5+=4; printf("%c%c%c%c%c\n",c1,c2,c3,c4,c5); }
C++解答
#include<iostream> int main() { printf("Glmre"); return 0; }
Java解答
public class Main { public static void main(String[] args) { String s = "China" ; char c[] = s.toCharArray() ; for (int i = 0; i < c.length; i++) { System.out.print((char)(c[i]+4)) ; } } }