Home > Backend Development > C#.Net Tutorial > A simple tutorial suitable for beginners to get started with C language

A simple tutorial suitable for beginners to get started with C language

烟雨青岚
Release: 2020-06-18 17:52:50
forward
3147 people have browsed it

A simple tutorial suitable for beginners to get started with C language

A simple tutorial suitable for beginners to get started with C language

CDeclaration of language data variables

The declaration of integer variables uses int, such as: int a;

The declaration of single-precision floating point types uses float, such as: float b;

Use double to declare double-precision floating point type, such as: double c;

CBasic input and output of language

Use scanf() to input data from the keyboard,

The calling format is: scanf(“%d”, &a);scanf(“%f”, &b);scanf(“%lf”, &c) ;

Use printf() to output data to the screen

The calling format is: printf(“%d %f %lf”,a,b,c);

Output “hello world”

#include<stdio.h>
int main()
{
    printf("hello world");
    return 0;
}
Copy after login

Simple numerical calculation:

#include<stdio.h>        //包含一个头文件stdio.h以完成程序的基本输入输出

int main()     //程序主函数,每个程序必须要有的部分

{    //语句框,表示框内的语句属于主函数,在主函数声明的变量只在主函数内部有效

    int a,a1=1;    //声明整形变量a和a1,并直接给a1赋初值为1(使用任何变量都必须先声明后使用)

    a=2;    //给声明过的整形变量a赋值为2

    float b,b1=1.5;   //声明单精度浮点类型变量b和b1,并直接给b1赋初值为1.5

    b=3.5;           //给声明过的单精度浮点数b赋值为3.5

    double c,c1=2.5;   //声明双精度浮点类型变量c和c1,并直接给c1赋初值为2.5

    c=4.5;            //给声明过的双精度浮点数c赋值为4.5

    double d=a+b+c+a1+b1+c1;   //声明一个双精度浮点数d,并把a+b+c+a1+b1+c1的值赋给d

    printf("%lf",d);     //输出d

    scanf("%d %f %lf",&a,&b,&c);   //从键盘上输入三个值,并分别重新赋给a,b,c,其中%d %f %lf称为占位符,其分别为整型、单精度浮点型、双精度浮点型的占位符表示形式

    printf("%d %f %lf",a,b,c);       //输出a,b,c

    return 0;                     //主函数(main函数)结束的标志

}
Copy after login

The difference between single-precision floating-point number (float) and double-precision floating-point number (double):

01.The number of bytes occupied in the memory is different

Single-precision floating-point numbers occupy 4 bytes in the machine’s memory

Double-precision floating-point numbers occupy in the machine’s memory 8 bytes

02.The number of significant digits is different

Single precision floating point number valid digits8digits

Double precision floating point number valid digits 16bit

03.Value range

The representation range of single-precision floating-point numbers: -3.40E 38~3.40E 38

Double-precision floating-point numbers The representation range: -1.79E 308~-1.79E 308

04. in the program Processing speeds vary

Generally speaking,CPUprocesses single-precision floating-point numbers faster than double-precision floating-point numbers

Thank you all for reading, I hope you will benefit a lot.

This article is reproduced from: https://blog.csdn.net/qq_40907279/article/details/81514459

Recommended tutorial: "C Language

The above is the detailed content of A simple tutorial suitable for beginners to get started with C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template