C Practice Example 89
Title:A company uses public telephones to transmit data. The data is a four-digit integer, which is encrypted during transmission. The encryption rules are as follows: Add 5 to each digit, then replace the digit with the remainder of the sum divided by 10, then swap the first and fourth digits, and swap the second and third digits.
Program analysis:None.
Program source code:
Example
// Created by www.example.com on 15/11/9.
// Copyright © 2015 Example. All rights reserved.
//
#include <stdio.h>
int main()
{
int a,i,aa[4],t;
printf("Please enter four digits:");
scanf("%d",&a);
aa[0]=a%10;
aa[1]=a%100/10;
aa[2]=a%1000/100;
aa[3]=a/1000;
for(i=0;i<=3;i++)
{
aa[i]+=5;
aa[i]%=10;
}
for(i=0;i<=3/2;i++)
{
t=aa[i];
aa[i]=aa[3-i];
aa[3-i]=t;
}
printf("Encrypted number:");
for(i=3;i>=0;i--)
printf("%d",aa[i]);
printf("\n");
}
The output of the above example is:
请输入四位数字:1234 加密后的数字:9876other extensions