The three basic structures in C language programs are: 1. Sequential structure, which refers to execution in program order; 2. Selection structure, which refers to selecting the branch direction based on the judgment result; 3. Loop structure, which refers to a loop Body, you can decide how many times to loop based on the judgment conditions.
#The operating environment of this article: Windows 7 system, Dell G3 computer, C11 version.
There are three types of program structures in C language: sequential structure, selection structure, and loop structure. Next, in the article, we will introduce the usage of these three basic structures in detail, which has a certain reference effect. I hope it will be helpful to everyone.
In C language programs There are three program structures: sequential structure, selection structure (branch structure), and loop structure
Sequential structure:
The sequential structure is one sentence after another from beginning to end. Execute it until the last sentence is executed. As shown below
Example: Enter an uppercase letter from the keyboard and request to use lowercase letters instead
#include<stdio.h> int main() { char x,y; scanf("%c",&x); if(x >= 'A' && x <= 'Z') { y=x+32; } else { printf("this is a erro"); } printf("%c\n",y); return 0; }
Select structure
After arriving at a certain node, the branch direction to be executed will be determined based on the result of a judgment. As shown in the figure below
Example: Enter three numbers, and then arrange them from small to large
#include<stdio.h> int main() { float a,b,c,tmp; scanf("%f %f %f",&a,&b,&c); if(a > b) { tmp=b; b=a; a=tmp; } if(a > c) { tmp=c; c=a; a=tmp; } if(b > c) { tmp=c; c=b; b=tmp; } printf("%5.2f %5.2f %5.2f\n",a,b,c); return 0; }
[Recommended courses:C language tutorial】
Loop structure
The loop structure has a loop body , the loop body is a piece of code. For loop structures, the key is to decide how many times to execute the loop body based on the judgment result;
Example: Calculate 1 2 3 ···· 10
#include <stdio.h> int main(void) { int i, sum; printf("i = %d.\n", sum); for (i=0,sum=0; i<=10; i++) { sum += i; } printf("sum = %d.\n", sum); return 0; }
Summary: The above is the entire content of this article, I hope it will be helpful to everyone.
The above is the detailed content of What are the three basic structures in C language?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools
