A, PTA operations summary
(A) the title is not too fat 7-4
1, experiment code
#include <stdio.h> int main() { int a; float b; scanf("%d", &a); b=(a-100)*0.9*2; printf("%.1f",b); return 0; }
2, design ideas
(1) described in the text
Step 1: Enter the frame;
Step Two: Define two variables: a represents the height, is defined as a positive integer int type, b represents the weight of said nominal height, output request is one decimal place, it is defined to float;
The third step: scanf calls a method of an input value, the input is an integer of "% d", a fetch address is assigned a & a;
The fourth step: calculation formula b = (a-100) * 0.9 * 2, to give the corresponding value b;
Step five: one decimal output requirements, so "% .1f", the print result calculated value of b;
(2) Scheme
3. Problems encountered this problem debugging process and solutions
The definition of a, b forget output when requirements are defined as int type, how to submit not right, after careful examination correct;
printf when forgotten, before the program will run error, the red line is the wrong place to write the missing, filled out after the first fight and the next frame;
Write error "% f" output, the output after the decimal point six zero, check the condition of the subject plus "% .1f" corrected later.
(B) the price ladder 7-1
1, experiment code
#include<stdio.h> int main(){ float use,cost; scanf("%f",&use); if(use<=0){ printf("Invalid Value!"); } else if(use>0&&use<=50){ cost=0.53*use; printf("cost = %.2f",cost); } else if(use>50){ cost=0.53*50+(0.53+0.05)*(use-50); printf("cost = %.2f",cost); } return 0; }
2, design ideas
(1) described in the text
Step 1: Enter the frame;
Step Two: Define two float variables, use for the month electricity consumption, cost of electricity represents cope value, defined as the float has a decimal type;
The third step: use the input value;
Step Four: Analyzing use Size: less than or equal to 0, the end of the determination, an output ,; greater than 0 and less than or equal to 50 into the formula "cost = 0.53 * use" get the value of the cost, the output end of cost; "Invalid Value!"
use of greater than 50 "cost = 0.53 * 50 + (0.53 + 0.05) * (use-50)", and outputs the calculated cost program ends.
(2) Scheme
3. Problems encountered this problem debugging process and solutions
use and cost types are float, use the input format% f;
else-if the cycle, if the conditions are, the unconditional else;
Three cases are calculated and printed printf () output, the printf not use the same;
cost =% f, are spaces.
Second, the summary and study the progress bar
1, (1) starting to learn C language, we first learn the basic print statements printf (), defines three types of variable data int, float, double, respectively applied to different types of data and output results,
又学习了格式化输入函数scanf(),取被输入变量的地址为变量赋值,和输入多个数据,然后学习了计算分段函数的三种方法:if-else语句,嵌
套if-else语句和else-if语句,三种逻辑运算符:与&&、或||、非!,定义字符型数据char,switch-case语句,还有最重要的是for循环结构。
(2)在学习过程中紧跟老师的脚步,课下认真完成作业就能对所学知识基本掌握,但是总有很多小问题,比如定义类型不对,忘写分号,数和括号中间
用*乘号连接等小细节不加注意就会程序错误,for循环相关知识还没掌握牢,打开运行框太多软件崩溃等情况都表明新手还没熟练。
(3)多写程序多练习,熟能生巧;在写语句时先把框架打好,先写分号避免忘记;多做for循环相关题型;在写程序前先画流程图以便更加清晰的理解
程序。