Home>Article>Backend Development> What are the three basic program structures of C language?

What are the three basic program structures of C language?

王林
王林 Original
2020-11-12 11:22:25 62872browse

The three basic program structures of C language are: 1. Sequential structures, such as expression statements, function call statements, and compound statements; 2. Selection structures, such as if statements; 3. Loop structures, such as for statements , while statement, do while statement.

What are the three basic program structures of C language?

1. Sequential structure

Expression statement, empty statement, function call statement, compound statement

(related video Share:java video tutorial)

Program example:

Input an uppercase letter from the keyboard and request to use lowercase letters for output.

#include 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; }

2. Selection structure

if statement program example:

Input three real numbers a, b, c, and output these three in order from small to large algebraic values number.

#include 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; }

3. Loop structure

while statement, do while statement, for statement

for statement example:

Calculation: 1 2 3... .. 100.

#include int main() { int i,x=1; for(i = 2;i <= 100;i++) { x+=i; } printf("%d\n",x); return 0; }

Related recommendations:C language tutorial

The above is the detailed content of What are the three basic program structures of C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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