#include<stdio.h>
#include<math.h>
int candp(int a,int b,int c)
{int r=1;
int s;
int i=1;
for(i=1;i<=b;i++)r=r*a;
printf("%d\n",r);
s=r%c;
printf("%d\n",s);
return s;}
void main()
{
int p,q,e,d,m,n,t,c,r
char s;
printf("please input the p,q:");
scanf("%d%d",&p,&q);
n=p*q;
t=(p-1)*(q-1);
printf("the n is %12d\n",n);
printf("please input the e:");
scanf("%d",&e);
while(e<1||e>n) //此處修改為while循環
{
printf("e is error,please input again:");
scanf("%d",&e);
}
d=1;
while(((e*d)%t)!=1) d++;
printf("then caculate out that the d is %d\n",d);
printf("the cipher please input 1\n");
printf("the plain please input 2\n");
scanf("%c",&s);
while((s-'0')!=1&&(s-'0')!=2) //消除後面的getchar() 此處增加while循環註意括號內的字符
{scanf("%c",&s);}
switch(s-'0')
{
case 1:printf("intput the m:");
scanf("%d",&m);
c=candp(m,e,n);
printf("the plain is %d\n",c);break;
case 2:printf("input the c:");
scanf("%d",&c);
m=candp(c,d,n);
printf("the cipher is %8d\n",m); break;
}
}