C Programming lab report
Name: Kung
Experimental Location: home
Experiment time: 2019.3.9
Experimental project: a character code and ASCLL ; application operator of the expression ; the sequence structure of the application ; mathematical function ; chickens and rabbits with cage ; determining the coordinates .
1, experimental purposes and requirements
1, experimental purposes and requirements |
Master ++ increment, decrement - operators used correctly.
Master basic input / output functions of the basic functions of the calling method, input / output control of a predetermined format and the like.
Master the method described algorithm structured program.
C language proficiency of the operator, i.e., operator precedence and tuberculosis, operation rule, type of operands.
Second, the experimental content
Second, the experimental content |
1、实验练习:
Character code and ASCLL
1. brief description of the problem: Input Output Input Output characters written with different values
2. Experimental Code:
#include<stdio.h>
int main()
{
//第一种写法
char ch;
printf("请输入一个大写字母");
ch=getchar();
printf("小写字母为\n") ;
putchar(ch+31);
putchar(ch+32);
putchar(ch+33);
//第二种写法
scanf("%c",&ch);
printf("%c,%c,%c\n",ch+31,ch+32,ch+33);
//程序改进:计算平均值并输出
printf("%c",(ch+31+ch+32+ch+33)/3) ;
}
3. Analysis: input the character can be employed sacnf("%c",&字符变量)
+ printf("%c",&字符变量)
written; and may also be used ch=getc(stdin)``ch=getch()``ch=getchar()
input, putc()``putch()``putchar()
output.
2、实验练习:
Application of the operator of the expression
1. brief description of the problem: the original data is broken
2. Experimental Code:
#include<stdio.h>
int main()
{
int i,j,k;
printf("请输入一个三位数");
scanf("%d",&i) ;
//第三位
k=i%10;
//第二位
j=(i%100-k)/10;
//第一位
i/=100;
printf("%d %d %d",k,j,i);
return 0;
}
3. Analysis: At the time of data processing, and sometimes destroy data, then the data will be used next to the problem;
Solution 1: definition of a variable to store the data, and then destroyed when the variable retrieval;
Solution 2: Use the first final destruction.
3、实验练习:
Calculation of medical expenses
1. brief description of the problem: None
2. Experimental Code:
#include<stdio.h>
int main()
{
float i,j,k,x,y,z;
printf("请输入西药费,检查费,材料费,床位费,观察费,护理费:\n");
scanf("%f,%f,%f,%f,%f,%f",&i,&j,&k,&x,&y,&z);
float sum;
sum=i+k+j+x+y+z;
printf("应付款(元):%.2f病人付款(元):",sum);
int pay;
scanf("%d",&pay) ;
printf("计算结果:\n病人付款=%d元\n应收款=%.2f元,应找回%.2f元",pay,sum,pay-sum);
return 0;
}
3. Analysis: None
4、实验练习:
Mathematical Functions
1. brief description of the problem: the variable digital hybrid computing expression
2. Experimental Code:
#include<stdio.h>
int main()
{
float x;
float y;
printf("请输入x的值:") ;
scanf("%f",&x);
if(x<1){
y=x;
}else if(x<10){
y=2*x-1;
}else{
y=3*x-1;
}
printf("y的值为%2f",y);
return 0;
}
3. Analysis: In the calculation of y=2x-1
the input of the code when it should be y=2*x-1
, *
can not miss!
5、实验练习:
Chickens and rabbits with cage
1. brief description of the problem: the same problem and fourth experiments
2. Experimental Code:
#include<stdio.h>
int main()
{
int h,f,x,y;
printf("鸡兔总数,鸡兔脚总数:") ;
scanf("%d %d",&h,&f) ;
if(x>0&&y>0) {
x=(4*h-f)/2;
y=(f-2*h)/2;
printf("鸡有%d 兔有%d\n",x,y) ;
}else{
printf("输入错误!\n");
}
return 0;
}
3. Analysis: The same experiment 4.
6、实验练习:
Determining the coordinates
1. brief description of the problem: the expression of distance
2. Experimental Code:
#include<stdio.h>
int main()
{
float x,y;
printf("请输入一个点(x,y):");
scanf("%f,%f",&x,&y);
if(x<0) {
x=-x;
}
if(y<0) {
y=-y;
}
if(((x-2)*(x-2)+(y-2)*(y-2))<1){
printf("10");
}else{
printf("0");
}
return 0;
}
3. Analysis: This is the most complex experiments to determine if the condition, at the beginning I use to calculate the distance from the origin to the center, to be used #include<math.h>
in the sqrt
representation root. But there are drawbacks, so use the second method: Write the circle equation, <R
is the point within the circle. But pay attention to all the negative to positive.
Third, test summary
Third, test summary |
The experiment which is mainly to consolidate the basic C language written, some of the minutiae of error deepened the impression.
At the same time also studied writing markdown of (this post is written by markdown):
title:
# 一级标题
## 二级标题
### 三级标题
style:
*斜体*
**粗体**
==高亮==
~~删除线~~
and many more