# Pascal程序设计（二级）——基础篇01介绍课程

2016-11-05 19:32:37来源:CSDN作者:baidu_32651739人点击

int l3=0,l1=1,l2;
while (l1--&&l2==10,l3+=2,l2++<15);    /*这里如果"=="换成"="就会编译错误*/
printf("%d/n",l1+l2+l3);

#include<stdio.h>

/*这个程序只能算到12！*/

void main()
{
long int n,m,t;
scanf("%d",&n);
m=1;t=n;
while (n>=1)
{
m=m*n;
n--;
}
printf("%d!=%d/n",t,m);
}

/*******************************************************************
This program is used to computer n! , here n>=0 and n<=42900.
If use double to  computer n! then n must be less than 171 and if
n>=22 the n! is not accurate.(19000! contains 73048 decimal bits

and ending with 4749 zeros)
30000! contains 121288 decimal bits.
*******************************************************************/

#include"stdio.h"
#define HT 100000l
#define MAXEP 479001600l                                   /* 479001600 which can be represented in long (4 bytes) */
#define UPV 12
#define MAXA 160001l
#define MAXN 42901l

void printbig(int n,unsigned long r[],unsigned long newup)
{
int j=1,k,bits;
if(newup>=MAXA)
{
printf("%d is too big and %d! is more than 10^800000/n",n,n);
return;
}
else
{
printf("/n %d!=/n",n);
printf("%5d",r[newup]);
if(r[newup]>=10000)
bits=5;
else
if(r[newup]>=1000)
bits=4;
else
if(r[newup]>=100)
bits=3;
else
if(r[newup]>=10)
bits=2;
else
bits=1;
for(k=newup-1;k>=0;k--)
{
printf("%05d",r[k]);                                /* 1. */
if(++j%12==0)
printf("/n");
}
printf("/n");
}
printf("(contains %d decimal bits)/n/n",bits+(j-1)*5);
return;
}

void eval_small(int n)
{
int i,s=1;
for(i=1;i<=n;i++)
s*=i;
printf("%d!=%d/n",n,s);
}

void eval_big(int n)
{
static int lastn=MAXN;
static unsigned long r[MAXA],newup;
int i,j,k,t;
if(n>=lastn)
for(j=lastn+1;j<=n;j++)
{
for(k=0;k<=newup;k++)                     /* 2. */
r[k]*=j;
for(k=0;k<=newup;k++)                     /* 3. */
{
t=r[k]/HT;
r[k]%=HT;
r[k+1]+=t;
}
if(r[newup+1])                            /* 4. */
newup++;
}
else
{
/* cannot use the last result */
r[0]=MAXEP%HT;
r[1]=MAXEP/HT;
for(i=2;i<MAXA;i++)
r[i]=0;
newup=1;
for(j=UPV+1;j<=n;j++)
{
for(k=0;k<=newup;k++)
r[k]*=j;
for(k=0;k<=newup;k++)
{
t=r[k]/HT;
r[k]%=HT;
r[k+1]+=t;
}
if(r[newup+1])
newup++;
}
}
printbig(n,r,newup);
lastn=n;
return;
}

void main()
{
int i;
printf("Input a non_negative integer (0 to quit !): /n");
scanf("%d",&i);
while(i)
{
if(i>=MAXN)
printf(" i (%d) is too big ! Try again!/n",i);
else
if(i<=UPV)
eval_small(i);
else
eval_big(i);
printf("Input a non_negative integer (0 to quit !):/n");
scanf("%d",&i);
}
}

Delphi不是WINDOW环境吗？？是的，但是二级Delphi教学内容丰富，但却把教语言与编一本编译环境等同了，小基础们学习时就像才学编程语言就要编写个求大数的阶乘程序一样，苦闷啊，以前的DOS版Pascal教程的逻辑层次多好啊，讲究循序渐进，现在的国家二级C语言2016版的也很不错，WINDOW环境，但是教学是循序渐进的！！！！所以要把以前的和现在的二级Pacal语言教学的优点综合一块，循序渐进的编写教材与教育教学！！