我想制作一个数字凯撒密码。(所有数字加3)
输入: 52 输出: 85
输入: 954 输出: 287
输入: -10457 输出: -43780
如果有人能帮助我,我会非常高兴。
我尝试过这个程序,但当我输入少于5位数的数字时,它会在开头输出3。
当我输入52时,它输出33385。我还想问用户程序是否应接受新数字或退出。
输入: 52 输出: 85
输入: 954 输出: 287
输入: -10457 输出: -43780
如果有人能帮助我,我会非常高兴。
我尝试过这个程序,但当我输入少于5位数的数字时,它会在开头输出3。
当我输入52时,它输出33385。我还想问用户程序是否应接受新数字或退出。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number, operation;
printf("Enter the number: ");
scanf("%d", &number);
printf("%d", ((number / 10000) + 3) % 10);
printf("%d", (((number % 10000) / 1000) + 3) % 10);
printf("%d", (((number % 1000) / 100) + 3) % 10);
printf("%d", (((number % 100) / 10) + 3) % 10);
printf("%d\n", ((number % 10) + 3) % 10);
printf("press 1 to continue or 2 for exit.");
scanf("%d", &operation);
switch (operation) {
case 1:
printf("Enter the number: ");
scanf("%d", &number);
printf("%d", ((number / 10000) + 3) % 10);
printf("%d", (((number % 10000) / 1000) + 3) % 10);
printf("%d", (((number % 1000) / 100) + 3) % 10);
printf("%d", (((number % 100) / 10) + 3) % 10);
printf("%d\n", ((number % 10) + 3) % 10);
break;
case 2:
break;
}
return 0;
}