📄 求整数的质因数分解(有数组).c.txt
字号:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define Maxtimes 4
char Date[]={"2006.5.20"};
int zhg_entrance(char mima[],char prompt[])
{
char password[21]; // 由此可以更改允许用户输入的密码位数,实际密码位数应当在数组mima[]赋值处更改
extern char Date[]; // 声明外部变量
int i,j;
zhg_information(Date); // 外部变量Date[]已经在主调函数外赋过值 // zhg_information有清屏功能
printf("\n\t\t\t ");
printf("Welcom to use this program !\n\n\n");
printf("\tYou are given %d times to login at most.\n",Maxtimes); // 欲更改次数可在本程序首预处理命令处进行
printf("\t\t\t\t\t\t For PROMPT,press <Ctrl+P>.\n");
printf("\t\t\t\t\t\t For EXIT,press <Ctrl+E>.\n\n\n\n\n");
printf("\t Please input the password: ");
shurumima1: i=0;
do
{
password[i]=getch();
if(password[i]=='\b')
{
putchar('\b');
i--;
}
else
{
printf("\a*");
i++;
}
}
while(password[i-1]!='\r'&&password[i-1]!='\x10'&&password[i-1]!='\x05');
{
if(password[i-1]=='\x10') // <Ctrl+P>键
{
zhg_information(Date);
printf("\n\n\n\n\t\t\tPROMPT:%s\n\n\n\n\n\n\t\tContinue : ",prompt);
goto shurumima1;
}
if(password[i-1]=='\x05') // <Ctrl+E>键
return 0; // 表示登录失败
{
password[i-1]='\0';
if( strcmp(password,mima)==0 )
return 1; // 表示登录成功
}
}
for(j=1;j<Maxtimes;j++)
{
zhg_information(Date);
printf("\n\n\t\t\t\tPassword Error !\n");
if(Maxtimes-j>1)
printf("\n\t\t\t\t%d times left !\n",Maxtimes-j);
else
printf("\n\t\t\tFor the last time.Be careful !\n");
printf("\t\t\t\t\t\t For PROMPT,press <Ctrl+P>.\n");
printf("\t\t\t\t\t\t For EXIT,press <Ctrl+E>.\n\n\n\n");
printf("\tPlease input the password again: ");
shurumima2: i=0;
do
{
password[i]=getch();
if(password[i]=='\b')
{
putchar('\b');
i--;
}
else
{
printf("\a*");
i++;
}
}
while(password[i-1]!='\r'&&password[i-1]!='\x10'&&password[i-1]!='\x05');
{
if(password[i-1]=='\x10') // <Ctrl+P>键
{
zhg_information(Date);
printf("\n\n\n\n\t\t\tPROMPT:%s\n\n\n\n\n\n\t\tContinue : ",prompt);
goto shurumima2;
}
if(password[i-1]=='\x05') // <Ctrl+E>键
return 0;
{
password[i-1]='\0';
if( strcmp(password,mima)==0 )
return 1;
}
if(j==Maxtimes-1) // 此条件比以上两个的“优先级别”低不能放在其前
{
zhg_information(Date);
printf("\n\n\n\t\t Sorry,you've tried for %d times.\n\n",Maxtimes);
printf("\t\t\t Welcom to use next time !\n\n\n\n\n");
printf("\t\tPlease press any key to quit. Thank you !");
getch();
return 0;
}
}
}
return 1; // 事实上程序运行不到这里,此处是为了避免编译的警告
}
void zhg_information(char Date[])
{
int i;
clrscr();
printf("\n\t\t\t All Rights Reserved !!!\n");
printf(" Wuhan University\t\t\t\t\t\t----Author: zhg\n");
printf(" E-mail: wudazhg@163.com%55s\n",Date);
for(i=1;i<=80;i++)
putchar('-');
putchar('\n');
}
#include<math.h>
#define N 16
void main()
{
int i,fan,b,n,k,r,a[N]={0};
char mima[]={"87343609"},prompt[]={"dianmi"};
fan=zhg_entrance(mima,prompt);
if(fan==0)
goto over;
printf("Please input the number b(%%d) :\t");
scanf("%d",&b);
printf("b=%d",b);
n=b;
i=0;
for(k=2;k<=sqrt(n);k++)
{
r=n/k;
if(n%k==0)
{
n=r;
a[i]=k;
k--;
}
i++;
}
a[i]=n;
i=0;
xunhuan1:if(a[i]!=0)
printf("\nb=%d",a[i]);
else
{
i++;
goto xunhuan1;
}
xunhuan2: i++;
if(a[i]!=0)
printf("*%d",a[i]);
if(i>15)
goto over;
goto xunhuan2;
over:putchar('\n');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -