编译原理的练习题,会的帮下忙。

编译原理的练习题,会的帮下忙。,第1张

1、编译方法中自底向上的语法分析算法有:简单优先分析算法、算符优先分析算法、SLR方法、LR(K)方法、LALR(K)方法,自顶向下的语法分析算法有:递归子程序法、LL(K)分析算、预测分析方法。

2、词法分析器的输入是源程序的字符流,输出是词法记号流。

3、等价

4、(a|b)*(aa|bb)(a|b)*

14:

1#include<stdio.h>

main()

{ int i,j

for(i=0i<9i++)

{ j=i*10+6

if(j%3==0)

printf("%d\n",j)

continue

}

}

2)#include<stdio.h>

main()

{ int j,s,p,n

scanf("%d",&n)

for(s=p=0,j=1j<=nj++)

{p=p+j

s=s+p

}

printf("%d",s)

}

13

#include<stdio.h>

void main()

{int i,a,b,c,d,e,n

for(i=10000i<=99999i++)

{ a=i/10000

b=i/1000%10

c=i/100%10

d=i/10%10

e=i%10

if (a==e&&b==d)

printf("%-8d",i)

n++

}

if(n%5==0) printf("\n")

}

12

#include <stdio.h>

void main()

{

long int num

int indiv,ten,hundred,thousand,tenthousand,place

printf("请输入一个整数(0-99999):")

scanf("%ld",&num)

if(num>9999)

place=5

else if(num>999)

place=4

else if(num>99)

place=3

else if(num>9)

place=2

else place=1

printf("place=%d\n",place)

printf("每位数字为:")

tenthousand=num/10000

thousand=(num-tenthousand*10000)/1000

hundred=(num-tenthousand*10000-thousand*1000)/100

ten=(num-tenthousand*10000-thousand*1000-hundred*100)/10

indiv=num-tenthousand*10000-thousand*1000-hundred*100-ten*10

switch(place)

{case 5: printf("%d,%d,%d,%d,%d",tenthousand,thousand,hundred,ten,indiv)

printf("\n反序数字为:")

printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,tenthousand)

break

case 4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv)

printf("\n反序数字为:")

printf("%d%d%d%d\n",indiv,ten,hundred,thousand)

break

case 3:printf("%d,%d,%d\n",hundred,ten,indiv)

printf("\n反序数字为:")

printf("%d%d%d\n",indiv,ten,hundred)

case 2:printf("%d,%d\n",ten,indiv)

printf("\n反序数字为:")

printf("%d%d\n",indiv,ten)

case 1:printf("%d\n",indiv)

printf("\n反序数字为:")

printf("%d\n",indiv)

}

}

11

#include<stdio.h>

main()

{ int n

printf("请输入 ASCII码值:\n")

scanf("%d",&n)

if(n<32)

printf("这是一个控制字符")

else if(n>=48&&n<=57)

printf("这是一个数字")

else if(n>=65&&n<=90)

printf("这是一个大写字母")

else if(n>=97&&n<=122)

printf("这是一个小写字母")

}

10

main()

{

long int i

int bonus1,bonus2,bonus4,bonus6,bonus10,bonus

scanf("%ld",&i)

bonus1=100000*0.1

bonus2=bonus1+100000*0.075

bonus4=bonus2+200000*0.05

bonus6=bonus4+200000*0.03

bonus10=bonus6+400000*0.015

if(i<=100000)

bonus=i*0.1

else if(i<=200000)

bonus=bonus1+(i-100000)*0.075

else if(i<=400000)

bonus=bonus2+(i-200000)*0.05

else if(i<=600000)

bonus=bonus4+(i-400000)*0.03

else if(i<=1000000)

bonus=bonus6+(i-600000)*0.015

else

bonus=bonus10+(i-1000000)*0.01

printf("bonus=%d",bonus)

}

9

#include<stdio.h>

main()

{ int n

printf("请输入年份:\n")

scanf("%d",&n)

if((n%400==0)||(n%4==0)&&(n%100!=0))

printf("这一年是闰年\n")

else

printf("这一年不是闰年\n")

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11521331.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存