计算机二级C语言考试Tips
计算机二级C语言:理解数据结构,多刷编程题目 #生活技巧# #工作学习技巧# #技能证书备考#
考试形式
0.1 怎么考?怎么判?
黑子曰:程序编写题目,在fun中编写并且一定要运行程序,为什么强调一定要运行呢?我们知道,程序有无数种写法,程序编写题如何判定是否正确呢?只有唯结果论!结果在哪?.dat文档
随之而来,有一种应试技巧:
1、直接F5运行程序即可创建out.dat:
2、找到输出.dat文档(点击答题文件夹即可找到):
3、手动写入正确结果,如下图所示
0.2 可以直接到.dat 手动操作的题目
以本节16题为例,
题目描述:例如, 字符串中原有的字符串为"abcdefg",则调用该函数后,串中的内容"gfedCba",是不是直接在.dat文件中写入gfedCba,如下图所示:
提交
提交后其实并不正确!!**为什么呢?**看代码
void main() { char a[N]; FILE *out; printf("Enter a string:"); gets(a); printf("The original string is:"); puts(a); fun(a); printf("\n"); printf("The string after modified:"); puts(a); strcpy(a,"Hello World!");//注意这里 fun(a);//注意这里 /******************************/ out=fopen("out.dat","w"); fprintf(out,"%s",a); fclose(out); /******************************/ } 123456789101112131415161718192021
特别注意,最后一次调用函数
strcpy(a,"Hello World!");//注意这里 fun(a);//注意这里 12
也就是说,最后一次调用函数是对Hello World!进行倒写
模拟软件运行满分!
0.3 无法直接到.dat 手动操作的题目
计算题!题目给个输入x输出多少多少,但是判卷时判定f(y),
本节 15题.3~n之间所有素数的平方根之和
#include <stdio.h> #include <math.h> double fun(int n) {int i,j,k;double SumAve = 0.0;for (i = 3; i <= n; i++){k = sqrt(i);for (j = 2; j <= k; j++)if (i%j == 0)break;if (j >= k+1)SumAve += sqrt(i);}return SumAve; } void main() {int n; double sum; FILE *out; printf("Input N="); scanf("%d",&n); sum=fun(n); printf("\n\nsum=%f\n\n",sum); /******************************/ out=fopen("out.dat","w"); fprintf(out,"%f\n",fun(180)); fclose(out); /******************************/ } 1234567891011121314151617181920212223242526272829303132
雕虫小技比不过真才实学,开始学习吧…
A程序填空题
填空题要结合输出,特别是printf中语言格式判定;填写完毕后建议运行一下(快捷键F5),否则可能不得分;例题 A程序填空题27.计算前n项之和
修改前
#include <stdio.h> #include <math.h> double fun(double x, int n) { double f, t; int i; /**********found**********/ f = ___1___; t = -1; for (i=1; i<n; i++) { /**********found**********/ t *= (___2___)*x/i; /**********found**********/ f += ___3___; } return f; } void main() { double x, y; x=2.5; y = fun(x, 15); printf("\nThe result is :\n"); printf("x=%-12.6f y=%-12.6f\n", x, y); } 1234567891011121314151617181920212223
修改后
#include <stdio.h> #include <math.h> double fun(double x, int n) { double f, t; int i; /**********found**********/ f = 1.0; t = -1; for (i=1; i<n; i++) { /**********found**********/ t *= (-1)*x/i; /**********found**********/ f += t; } return f; } void main() { double x, y; x=2.5; y = fun(x, 15); printf("\nThe result is :\n"); printf("x=%-12.6f y=%-12.6f\n", x, y); } 123456789101112131415161718192021222324
输出结果
**难度等级:**★☆☆☆☆
C程序编写题
例题 C程序编写题35.删除字符串中所有空格(雕虫小技足矣)
雕虫小技
结合函数功能以及main函数,可得只需修改
`char Msg[]="Input a string:"; // fun(Msg); fprintf(out,"%s",Msg); 1234
即可
void main() { char str[81]; char Msg[]="Input a string:"; int n; FILE *out; printf(Msg); gets(str); puts(str); fun(str); printf("*** str: %s\n",str); /******************************/ out=fopen("out.dat","w"); fun(Msg); fprintf(out,"%s",Msg); fclose(out); /******************************/ } 123456789101112131415161718
输出结果
step1: 打开程序>直接运行(F5快捷键);
step2:随便输入,关闭之
step3:按照格式修改out.dat文件并保存;注意找main函数中最后一次调用函数对应的部分:
step4:
case 考场:本题做完了;break;
case 模拟;交卷体验下满分快感;break;
例题 C程序编写题37.计算…log函数的引用说明为(雕虫小技失效)
雕虫小技
失效拉
void NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i, n ; double s ; fp = fopen("in.dat","r") ; wf = fopen("out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = fun(n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 12345678910111213141516
网址:计算机二级C语言考试Tips https://www.yuejiaxmz.com/news/view/461725
相关内容
C语言在生活中的应用 …C 语言程序设计心得:编程之路的探索与收获
中级会计职称考试
C语言小项目实践——日历程序
大量二手计算机图书出售
计算机网络技师 实操,机关事业单位技术工人计算机操作技师考试题库
C语言学习错题集(一)
【计算机毕业设计】287校园二手书交易平台
c语言printf输出格式
剖析C语言中a=a+++++a的无聊问题