C programming experiment REPORT

C programming experiment REPORT

Name: Zhou Manjie
experiment Location: Home
Lab time: 2020.03.12

A purpose and requirements of the experiment

1, master ++ increment, decrement - proper use of operators.
2, the basic control functions of the basic input / output functions, call the method, an input / output control of a predetermined format and the like.
3, the means to acquire the algorithm described structural program
4, C language proficiency of the operator, i.e., operator precedence and tuberculosis, operation rule, type of operands.

II. Experimental content

1, lab exercises: 2.3.3 and ASCII character code

A brief description of the problem: None
2 experiment code:

#include<stdio.h>
main()
{
    int a,b,c,d;
    printf("请输入一个大写字母:\n");
    scanf("%c",&a);
    b=a+32;
    c=b-1;
    d=b+1;
    printf("小写字母为:%c,%C,%C\n",c,b,d);
    printf("ASCII码的值为:%d,%d,%d",c,b,d);
}

Analysis 3: Note (a difference of 32 between uppercase and lowercase letters)

2, exercises: Application 2.3.4 Operators and expressions

A brief description of the problem: the use of rounded and take the remainder
2 experiment code:

#include<stdio.h>
main()
{
    int a,b,c,x,y;
    printf("请输入一个三位数的整数:\n");
    scanf("%d",&x);
    a=x/100;
    b=x%100/10;
    c=x%10;
    y=c*100+b*10+a;
    printf("%d:%d\n",x,y);
    return 0;
}

3 Analysis: Note the use of% /.

3. exercises: 2.3.5 sequential structure of the application

A brief description of the problem: the input switch
2 experiment code:

#include<stdio.h>
main() 
{
    float a,b,c,d,x,y,z,m,n;  /*a表示西药费,b表示检查费,c表示材料费,d表示床位费,x表示观察费,y表示护理费,z表示病人所付款数,m表示应付款数,n表示应找回金额*/
    printf("请输入西药费,检查费,材料费,床位费,观察费,护理费:\n");
    scanf("%f,%f,%f,%f,%f,%f",&a,&b,&c,&d,&x,&y);
    m=a+b+c+d+x+y;
    printf("应付款数(元):%.2f",m);
    printf("病人付款(元):");
    scanf("%f",&z);
    n=z-m;
    printf("计算结果:");
    printf("病人付款=%6.2f元\n应收款=%6.2f元,应找回=%6.2f元\n",z,m,n);
    return 0;
     
}

Analysis 3: Enter a comma after the word need to switch text input

4. exercises: Algorithms 3.3.1 mathematical functions

A brief description of the problem: None
2 experiment code:

#include<stdio.h>
main()
{
    float x,y;
    printf("请输入x的值:");
    scanf("%f",&x);
    if(x<1)y=x;
    else if (1<x&&x<10)y=2*x-1;
        else if(x>10)
        y=3*x-1;
        printf("y的值域为%.2f\n",y);
}

Analysis 3: None
4 is a flowchart:

5. exercises: 3.3.2 Algorithm Description chickens and rabbits with cage

A brief description of the problem: the need for a custom variable integer
2 experiment code:

#include<stdio.h>
main()
{
    int h,f,x,y;
    printf("鸡和兔的总数,鸡和兔脚的总数:");
    scanf("%d,%d",h,f);
    if(h>0&&f>0)![](https://img2020.cnblogs.com/blog/1940803/202003/1940803-20200312113320397-189462565.png)


    {
        x=(4*h-f)/2;
        y=(f-2*h)/2;
        printf("鸡有%d只 兔有%d只\n",x,y);
    }
    else
    {
        printf("数值错误!\n");
    }
    return 0;       
}

Analysis 3: Numerical error conditions exist
4 Flowchart:

6. exercises: 3.3.3 to determine the coordinates of the algorithm description

A brief description of the problem: a float
2 experiment code:

#include<stdio.h>
#include<math.h>
main()
{
    int h=10;
    float x1=1,y1=2,x2=-2,x3=-2,y2=2,y3=-2,x4=2,y4=-2,x,y,d1,d2,d3,d4;
    printf("请输入一个(x,y):");
    scanf("%f,%f",&x,&y);
    d1=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
    d2=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
    d3=sqrt((x-x3)*(x-x3)+(y-y3)*(y-y3));
    d4=sqrt((x-x4)*(x-x4)+(y-y4)*(y-y4));
    if(d1>1&&d2>1&&d3>1&&d4>1)
    h=0;
    else h=10;
    printf("该塔的高度为%d",h);
}

3 Analysis: need to be defined separately for each variable, and use the function.

Experiments Summary

In this experiment, the use MACKDOWN learned, and added thereto a flowchart there have been some problems, for example, in the English input switching, etc., is also familiar with the use of the function.

Guess you like

Origin www.cnblogs.com/absolutely-123/p/12468116.html