视力0.25近视严重吗:C程序高手,大侠请进来帮帮忙!

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 02:01:24
某个公司采用公用电话传递数据信息,数据是小于8位的整数.为了确保安全,在传递过程中需要加密.加密规则如下:
首先将数据倒序,然后将每位数字加上5,再用和除以10的余数代替该数字,最后将第一位和最后一位数字交换.要求通过实现数据加密的过程.
<这个程序该怎么改,我希望能简单化,用VC++改过来!>
#include <stdio.h>
#include <string.h>
int main()
{
char str[8]={'\x0'};
int i=0,j,temp;
short *memo=NULL;
long word;
printf("Please input the digital information:");
gets(str);
memo=(short *)malloc(sizeof(short)*strlen(str));
if(memo==NULL)
exit(1);
word=atol(str);
while(word>0)
{
memo[i++]=word%10;
word/=10;
}
for(j=0;j<i;j++)
{
memo[j]+=5;
memo[j]%=10;
}
temp=memo[0];
memo[0]=memo[i-1];
memo[i-1]=temp;
j=0;
while(j<i)
str[j++]=memo[j]+48;
str[j]='\0';
puts(str);
free(memo);
getch();
}
运用1.变量和数据类型 2.运算符 3.循环结构 4.数组

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char str[8]={'\x0'};
int i,j,temp;
short memo[32];
long word;
printf("Please input the digital information:");
gets(str);
word=atol(str);

i=0;
while(word>0)
{
memo[i++]=word%10;
word/=10;
}

for(j=0;j<i;j++)
{
memo[j]+=5;
memo[j]%=10;
}

temp=memo[0];
memo[0]=memo[i-1];
memo[i-1]=temp;

j=0;
while(j<i)
{
str[j++]=memo[j]+48;
}
str[j]='\0';

puts(str);
getch();
}

这个程序不行么,VC里也可以运行啊

不知道是否以零开头,如果不以零开头下面的程序应该可以
#include<iostream.h>

void main(){
int date,result,temp1;
int num[7];
cout<<"input the date"<<endl;
cin>>date;
temp1=date;
int i,n;
for(i=0;i<8&&temp1>=1;i++)
{
num[i]=temp1%10;
temp1=temp1/10;
}
n=i-1;
for(i=0;i<=n/2;i++)
{
int temp;
temp=num[i];
num[i]=num[n-i];
num[n-i]=temp;
}
for(i=0;i<=n;i++)
num[i]=(num[i]+5)%10;
int temp;
temp=num[0];
num[0]=num[n];
num[n]=temp;
temp1=num[n];
for(i=n-1;i>=0;i++)
temp1=temp1*10+num[i];
result=temp1;
cout<<" the final result is:"<<result<<endl;
}