作业讲评-2顺序程序设计.doc本章节作业共四题,主要考查的知识点为:顺序结构程序设计的框架、 数据类型、常数和常量的表示方法、变量的定义和使用方法、算术表 达式的写法、数学函数、基本输入/输出函数的用法等。
温度转换题 1
验证字节题 2
求利息 2
选做题答案(求四种数据类型表达的数据范围) 3
1、
温度转换题典型詹
•常见错误:
#include<>
void main()
int F;
float C;
•语句顺序错。
•强制转换错。
C-(float)(5/(9*(F-32)));printf(',Please intput F:\n”);
scanf("%d\n",F);
printf("%d\n",C);}
#include<> void main() int F;
float C;
printf("Please intput F:\n");
scanf("%f\n",&F);
C=(float) 5/9*(F-32);/*或 C=*(F-32); */ printf("%f\n",C);}
2、验证字节题
#include <> main()
{
printf("Data type printf("-
printf("char printf("int printf("short int printf("long int printf("float
printf("double
} char 1
int 4
short int 2
long int 4
float 4
Number of bytes\n");
\n");
%d\n", sizeof(char));
%d\n", sizeof(int));
%d\n", sizeof(short));
%d\n", sizeof(long));
%d\n", sizeof(float));
%d\n", sizeof(double));
double
83、求利息
#include<>
#include<>
#define RATE void main()
double year,capital,money;
pnntf("please input year, capital:");
scant ("%lf,%lf",&year, &capital);
money=capital*pow(1 +RATE,year);
printf("moneys%lf",money);
}广部分同学在红色标记的地方出错,请自己对照*i4、选做题
答案(求四种数据类型表达的数据范围)
#include <>
#include <>
void main()
{
inti;
long double term=1 ,fraction=1;
long double min,max; /*定义两个变量分别最小值、最大值*/
min=-pow(2,8* sizeof(char));
max=pow(2,8* sizeof(char))-1;
printf("char 所能表示的范由:%
作业讲评-2顺序程序设计 来自淘豆网www.taodocs.com转载请标明出处.