文档详情

C语言复习资料C语言复习资料.docx

发布:2017-12-14约1.91万字共28页下载文档
文本预览下载声明
C语言复习资料顺序结构程序1_1:实现从键盘输入一个整数,输出该数的平方。程序1_2:编程完成四则运算。如:输入 3.2 2.1输出 3.20+2.10=5.303.20-2.10=1.103.20*2.10=6.723.20/2.10=1.52参加运算的两个数应该从键盘输入;输出格式不对,注意每行输出一个运算;输出结果的样式应该和例如里面的完全一样。程序1_3:计算f (x) = ,并输出结果。输入输出0.763.5823.005.3693.768.931绝对值的运算有自己的函数,最好不要用平方再开方的方法来做;绝对值函数有两个,要注意参数的数据类型。F(x)只是一种写法而已,C语言的函数还没介绍,此处随便用一个变量来代替即可程序1_4:计算f (x) = ,并输出结果。输入输出0.762.1753.005.3073.769.111程序1_5:计算f (x) = ,并输出结果。程序1_6:输入一个三角形的三边长a,b,c,用公式(其中)计算三角形的面积,并打印输出。注意s的求法,1/2=0!。如果定义变量为double类型,注意scanf(“%lf”,x),而不是scanf(“%f”,x)scanf()、printf()中格式控制字符串与后面的变量名表列有两个对应:1、个数对应,2、类型对应程序答案1.#include stdio.hmain() { int x; printf(Please input a number:\n); scanf(%d,x); printf(%d*%d=%d\n, x,x,x*x); getch(); }2.#include stdio.h#include conio.hvoid main(){ int m,n; clrscr(); printf(Input two numbers: ); scanf(%d%d,m,n); printf(%d + %d = %d\n,m,n,m+n); printf(%d - %d = %d\n,m,n,m-n); printf(%d * %d = %d\n,m,n,m*n); printf(%d / %d = %d\n,m,n,m/n); getch();}3.#include stdio.h#include math.hmain() { float a,b,c,area,s; printf(Please input three numbers:); scanf(%f%f%f, a,b,c ); s = (a+b+c)/2; s = s*(s-a)*(s-b)*(s-c); if( s 0 ) area = -1; else area = sqrt(s); printf(Area is: %.2f\n,area); getch();}4.#include stdio.h#include math.hvoid main(){ int x; float f; printf(Input an integer: ); scanf(%d,x); f = (fabs(x)-2)/(x*x+1); printf(F(x)=%f\n,f);}5.#include math.h#include stdio.hvoid main(){ double x; printf(input a number:); scanf(%lf,x); x=(exp(x)+fabs(x-6))/(x+1.3); printf(%8.3lf\n, x);}6.#include math.h#include stdio.hvoid main(){ double x; printf(input a number:); scanf(%lf,x); x=(1+sin(x)+exp(x))/(1+x); printf(%8.3lf\n, x);}选择结构习题输入输出0.761.2003.0010.0003.768.520程序2_1:计算f (x) = ,并输出结果。程序2_2:输入一个三角形的三边长a,b,c,用勾股定理判断是否为直角三角形,打印输出结果。输入输出0.80.964.5107.05725-1.00程序2_4:计算f (x) = ,并输出结果。输入输出0.40.821.51.24780-1.00程序2_5:计算f (x) = ,并输出结果。输入输出1210.38732.2512.9350.1131.568程序2_6:计算f (x) = ,并输出结果。If 条件中是= =,不是=,与用表示,或用||表示300x500if 条件后面不能加分号,否则else无法与之匹
显示全部
相似文档