|
[讨论]DEV C++中初学者编程 共同学习者顶起来
高考学考马上又是中考 学生放假 布置了这套试题 有兴趣的朋友可试着做一做 : 自考“C语言程序设计”模拟试题一 2007年05月29日 13:52 来源:自考365 一、填空题 1、C语言中基本的数据类型有:______、______ 、______ . 2、C语言中普通整型变量的类型说明符为______,在内存中占______字节,有符号普通整型的数据范围是______ . 3、整数-35在机内的补码表示为______. 4、执行下列语句int a=8; a+=a-=a*a; 后,a的值是______. 5、有如下语句:char A[ ]={“I am a student”}; 该字符串的长度是______,A[3]=______. 6、符号“a”和‘a’的区别是______. 7、所谓“指针”就是______.“&”运算符的作用是______.“*”运算符的作用是______. 8、有如下输入语句:scanf(“a=%d,b=%d,c=%d”,&a,&b,&c);为使变量a的值为1,b的值为3,c的值为2,从键盘输入数据的正确形式应是______. 二、选择题 1、设整型变量a为5,使b不为2的表达式是( )。 A. b=a/2 B. b=6-(——a) C. b=a%2 D. b=a>3?2:1 2、为了避免嵌套的条件分支语句if-else的二义性,C语言规定:C程序中的else总是与( )组成配对关系。 A. 缩排位置相同的if B. 在其之前未配对的if C. 在其之前未配对的最近的if D.同一行上的if 3、以下程序的输出结果是( )。 int x=10,y=10; printf(“%d %d\n”,x——,——y); A. 10 10 B. 9 9 C. 9 10 D. 10 9 4、设A为存放(短)整型的一维数组,如果A的首地址为P,那么A中第i 个元素的地址为( )。 A.P+i*2 B. P+(i-1)*2 C. P+(i-1) D. P+i 5、选出下列标识符中不是合法的标识符的是( )。 A. hot_do B. cat1 C. _pri D. 2ab 6、以下程序的输出结果是( )。 int a=5; float x=3.14; a*=x*(‘E’ - ‘A’); printf(“%f\n”,(float)a); A. 62.000000 B. 62.800000 C. 63.000000 D. 62 7、设有说明double(*p1)[N];其中标识符p1是( )。 A. N个指向double型变量的指针。 B. 指向N个double型变量的函数指针。 C. 一个指向由N个double型元素组成的一维数组的指针。 D.具有N个指针元素的一维指针数组,每个元素都只能指向double型量。 8、在C程序中有如下语句:char *func(int x,int y);它是( )。 A. 对函数func的定义。 B. 对函数func的调用。 C.对函数func的原型说明。 D. 不合法的。 9、以下程序的输出结果是( )。 char str[15]=“hello!”; printf(“%d\n”,strlen(str)); A. 15 B. 14 C. 7 D. 6 10、分析以下程序的输出结果是( )。 main() {int a=5,b=-1,c; c=adds(a,b); printf(“%d”,c); c=adds(a,b); printf(“%d\n”,c); } int adds(int x,int y) {static int m=0,n=3; n*=++m; m=n%x+y++; return(m); } A. 2,3 B. 2,2 C. 3,2 D. 2,4 11、下列描述中不正确的是( )。 A. 字符型数组中可能存放字符串。 B. 可以对字符型数组进行整体输入、输出。 C. 可以对整型数组进行整体输入、输出。 D. 不能在赋值语句中通过赋值运算符“=”对字符型数组进行整体赋值。 12、以下程序的输出结果是( )。 #define f(x) x*x main() {int a=6,b=2,c; c=f(a)/f(b); printf(“%d\n”,c); } A. 9 B. 6 C. 36 D. 18 13、设有如下定义: int x=10,y=3,z; 则语句printf(“%d\n”,z=(x%y,x/y)); 的输出结果是( )。 A. 1 B. 0 C. 4 D. 3 14、定义如下变量和数组:int i;int x[3][3]={1,2,3,4,5,6,7,8,9}; 则语句for(i=0;i<3;i++) printf(“%d ”,x[i][2-i]); 的输出结果是( )。 A. 1 5 9 B. 1 4 7 C. 3 5 7 D. 3 6 9 15、以下对二维数组a进行正确初始化的是( ) A. int a[2][3]={{1,2},{3,4},{5,6}}; B. int a[ ][3]={1,2,3,4,5,6}; C. int a[2][ ]={1,2,3,4,5,6}; D. int a[2][ ]={{1,2},{3,4}}; 16、两次运行下面的程序,如果从键盘上分别输入6和3,则输出结果是( )。 int x; scanf(“%d”,&x); if(x++>5) printf(“%d”,x); else printf(“%d\n”,x - -); A. 7和5 B. 6和3 C. 7和4 D. 6和4 17、设有如下定义: char *aa[2]={“abcd”,“ABCD”}; 则以下说法中正确的是( )。 A)aa数组成元素的值分别是“abcd”和ABCD“ B)aa是指针变量,它指向含有两个数组元素的字符型一维数组 C)aa数组的两个元素分别存放的是含有4个字符的一维字符数组的首地址 D)aa数组的两个元素中各自存放了字符‘a’和‘A’的地址 18、下列程序的输出结果是( )。 char *p1=“abcd”, *p2=“ABCD”, str[50]=“xyz”; strcpy(str+2,strcat(p1+2,p2+1)); printf(“%s”,str); A. xyabcAB B. abcABz C. ABabcz D. xycdBCD 19、下列程序的输出结果是( )。 int a[5]={2,4,6,8,10},*P,* *k; p=a; k=&p; printf(“%d”,*(p++)); printf(“%d\n”,* *k); A. 4 4 B. 2 2 C. 2 4 D. 4 6 20、不能把字符串:Hello!赋给数组b的语句是( )。 A. char b[10]={‘H’,‘e’,‘l’,‘l’,‘o’,‘!’}; B. char b[10]; b=“Hello!”; C. char b[10]; strcpy(b,“Hello!”); D. char b[10]=“Hello!”; 三、读程序题 1、float f=3.1415927; printf(“%f,%5.4f,%3.3f”,f,f,f); 则程序的输出结果是 . 2、int x=6, y=7; printf(“%d,”,x++); printf(“%d\n”,++y); 程序的输出结果是 . 3、a=3; a+=(a<1)?a:1; printf(“%d”,a); 结果是. 4、for (a=1,b=1;a<=100;a++) { if(b>=20) break; if(b%3==1) {b+=3; continue;} b-=5; } 程序的输出结果a的值为 . 5、int y=1, x, *p, a[ ]={2,4,6,8,10}; p=&a[1]; for(x=0;x<3;x++) y + = * (p + x); printf(“%d\n”,y); 程序的输出结果y的值是 . 四、程序填空题 1、从键盘上输入10个数,求其平均值。 main() {int i; float f,sum; for(i=1,sum=0.0;i<11;i++) { ; ; } printf(“average=%f\n”,sum/10); } 2、以下程序是建立一个名为myfile的文件,并把从键盘输入的字符存入该文件,当键盘上输入结束时关闭该文件。 #include <stdio.h> main() { FILE *fp; char c; fp= ; do{ c=getchar(); fputs(c,fp); }while(c!=EOF); } 3、以下程序的功能是:从键盘上输入若干个学生的成绩, 统计并输出最高成绩和最低成绩,当输入负数时结束输入。请填空。 main() { float x,amax,amin; scanf(“%f”,&x); amax=x; amin=x; while( ) { if(x>amax) amax=x; if( ) amin=x; scanf(“%f”,&x); } printf(“\namax=%f\namin=%f\n”,amax,amin); } 五、编程题 1. 三个整数a、b、c,由键盘输入,输出其中最大的一个数。 2.输出1900~2000年中所有的闰年。每输出3个年号换一行。(判断闰年的条件为下面二者之一:能被4整除,但不能被100整除。或者能被400整除。) 3.请编一个函数int fun(int a),它的功能是:判断a是否是素数,若a是素数,返回1;若不是素数,返回0.A的值由主函数从键盘读入。 4.有N个学生,每个学生的信息包括学号、性别、姓名、四门课的成绩,从键盘上输入N个学生的信息,要求输出总平均成绩最高的学生信息,包括学号、性别、姓名和平均成绩。 |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
最近高考学考 有点忙 不能更新 望谅解 |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
佩服!! 继续细看你的算法, 妙!!! w=(w+m-1)%i; printf("%d",s[w]); 我改成这样适合我的编译软件了. 结果确实是正确的, 这前一句就是想不到啊 是怎么得出来的啊 小弟愚笨 呵呵 猜测: W相当于报数起点 W+M找到报数人 再减1就是数组脚标 对数组长度取模就够成 约瑟夫环 是这样的吗?? |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
谢谢楼上两位朋友支持 你的算法我看了,不错! 我后面发的那个程序中也用了这个, 只是我写的太啰嗦,漏洞也多,是为了调试和让那两个学生看懂!!我正在初步介绍数据结构和算法,但我学识太浅了,以后还望多多指点! 谢谢了!! |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
#include "stdio.h" #include "stdlib.h" #include "string.h" int main() { FILE *FP; FP=freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); char s[100],ss; int i,j,k; /* 从输入文件读取100位以内的四则混合标准后缀表达式 非标准可能计算错误 所谓标准如:(3+5)/2-5 要化成(((3+5)/2)-5) 全用小括号括起来 */ for(i=0;i<100;i++) { ss=fgetc(FP); if(ss==-1) break; /* 读取文件错误返回值是-1 用于跳出 */ s[i]=ss; } for(j=0;j<i;j++) printf("%c",s[j]); i--; printf("\ni=%d\n",i);printf("\ns[i+1]=%d\n",s[i+1]); /* 模拟中缀化后缀的栈操作 */ int z=0,h=0; char hou[100],zan[100],x,y; for(z=0,j=0;j<=i;j++) /* i是字符个数减了1 这决定牡环次数 */ { x=s[j]; printf("x=%c j=%d\n",x,j); /* 用于调试检查每步是否正确完成后删 */ if((x=='+')||(x=='-')||(x=='*')||(x=='/')||(x=='(')) /* 注意优先级 */ { zan[z]=x; z++; /* 这里字符数组赋值用X 不能用数组 */ } else if(x!=')') /* 三分支分别给出了三个情况分离 */ { hou[h]=x;h++; } else { y=zan[z-1]; while(y!='(') /* 这里当型循环的边界值以实例检验 */ {hou[h]=y;z--;h++;y=zan[z-1];} z--; } printf("zan[z]=%s\n",zan); printf("hou[h]=%s\n",hou); } /* 输出后缀表达式 */ printf("The long of h=%d\n",h); printf("The suffix expression is : %s\n",hou); } 错误一定有 望指正 |
|
|
|
|
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
我倒 那是PASCL 这里的是C |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
后缀表达式 用栈计算表达式的值 例:上题中表达式结果为28/3 后缀表达式: 15 6 2 * 5 - 3 / + 8 - 从左向右读这个后缀表达式,放入栈S中如图示 S栈 15 6 2 遇* 取2为Y 6为X X*Y结果入栈 15 12 继续读后缀式 15 12 5 遇- 取5为Y12为X X-Y=12-5=7 入栈 15 7 继续读后缀式 15 7 3 遇/ 取3为Y 7为X X/Y=7/3 入栈 15 7/3 继续读后缀式 15 7/3 遇+ 15+7/3 入栈 52/3 继续读后缀式 52/3 8 遇- 52/3 -8 入栈 28/3 结束 结果就是28/3 将后缀表达式读入栈, 遇运算符就取出两个操作数,先出的为Y,后出栈的为X 运算: X 运算符 Y =? 将结果又压入栈中,继续直到得出结果. 写C的源程 不知同仁中哪位有兴趣写一个出来哦!!! 我自己还没开始写,这两天较忙. 后面我会写一个出来. |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
好了 我们继续学习 上面学习到栈的例题了 中缀表达式化成后缀表达式怎么化?? 中缀表达式变后缀表达式方法: 例:15+(6*2-5)/3-8 先变成标准中缀表达式 ((15+(((6*2)-5)/3))-8) 后缀表达式 栈(用来放运算符,遇右括后弹仓至遇左括号) (( 15 (( 15 ((+ 15 ((+((( 15 6 ((+((( 15 6 2 ((+((( 15 6 2 ((+(((* 15 6 2 ((+(((* 遇)开始弹栈 15 6 2 * ((+(( 15 6 2 * 5 ((+(( 15 6 2 * 5 ((+((- 15 6 2 * 5 ((+((- 遇)开始弹栈 15 6 2 * 5 - ((+( 15 6 2 * 5 - 3 ((+( 15 6 2 * 5 - 3 ((+(/ 15 6 2 * 5 - 3 ((+(/ 遇)开始弹栈 15 6 2 * 5 - 3 / ((+ 遇)开始弹栈 15 6 2 * 5 - 3 / + ( 15 6 2 * 5 - 3 / + 8 ( 15 6 2 * 5 - 3 / + 8 (- 15 6 2 * 5 - 3 / + 8 (- 遇)开始弹栈 15 6 2 * 5 - 3 / + 8 - 此结果就是后缀表达式 自己在记事本中对齐了再看可能好一点儿 呵呵 每行一个变化。 规则是左边数字 右边运算符 遇右括号弹仓到左边消一个左括号。 这个搞清楚了,实际上就是一个算法,后面就可写出C的运行程序将中缀表达式转换成后缀表达式。 |
|
|
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
43楼的这个问题 有高手解释没有?? 本来应是当型循环 怎么运行趣来是 直到型循环一样的效果了 !! #include <stdio.h> int main() { freopen("out.txt","w",stdout); int k,n,m; n=10;m=1;k=1; while (k++<=n) { m*=2; printf("k++=%d m=%d \n",k,m); } printf ("%d\n",m); } |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
另 发布前一例题表达式问题的求解思路: 例题为栈的运用, 要求用栈的方法计算表达式的值. 所以解题过程应是: 1、将中缀表达式转化成标准式,即按算的先后添加小括号 2、将标准中缀表达式用栈转化成后缀表达式 3、用栈计算后缀表达式,求出表达式的值。 |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
程序运行结果是这样的: k++=2 m=2 k++=3 m=4 k++=4 m=8 k++=5 m=16 k++=6 m=32 k++=7 m=64 k++=8 m=128 k++=9 m=256 k++=10 m=512 k++=11 m=1024 很明显, 在条件中是先K=K+1, 然后再比较, 而结果也应是1024; 从上表中,你会发现运行循环体是在条件之前的. k++=11,时运行了m*=2 再运行条件比较,再就退出循环 因为这是直到型循环的表现 但这种写法一定是当型循环 我晕晕了 |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
前题中的表达式问题: 表达式分为:中缀表达式与后缀表达式 中缀表达式就和我们生活中习惯的表达式差不多,括号只用小括号. 后缀表达式是运算符在两个计算数的后面. 例: 23+(3*5-1)/2-5 是中缀表达式 23 3 5 * 1 - 2 / + 5 - 是后缀表达式 这些有谁熟悉吗? |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
C语言上有什么问题 我希望大家拿到这里来讨论 说实在的 我也算是初学者 因为自学进度太慢了 所以这长时间下来 我也还在打基础 大家有东东拿出来,在这里大家都能看到,会则跳过,不会则学习。只有这样我们才有大量看源程序的机会, 才有一定的程序经验。 不要怕人家说什么, 只要是不会的 一句也可以拿出来讨论。 共同加油!!!!! |
|
[分享]驱动开发视频教程 [免KEY版]
好东西 谢谢分享 |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
栈练习题1: 一个数学表达式由下列元素组成:左括号,右括号,加号,减号,乘号,正号,负号,整数(无前导0)。给出一个长度不超过100的数学表达式,求它的值,要求考虑括号和乘法的优先级,计算过程中的临时值的绝对值保证不会超过 。给出的表达式保证合法以及符合人的书写习惯(但可能会有多余的括号对)。以下表达式被认为是合法的:((10+(-100))) ,-3*(+5+7*2)-(0) ,-0 ,(-3)*(-5+7)。以下表达式被认为非法:1+-7 ,--3+8 ,-3+() 。 用程序做一做。 |
|
[讨论]DEV C++中初学者编程 共同学习者顶起来
今天开始练习栈 外特性:后进先出(LIFO) 运用方面: 交卷子 KTV的“点歌单” 作用:保护现场 逻辑结构:只在一端操作的线性表 数组实现: 元素 stack : array[1..maxn] of integer 栈顶指针 top 练习题接着出来 |
|
|
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值