开始就是简单的顺序结构 选择结构 循环结构
都很容易理解 我如今使用的编译器为 MSVC2019 企业版
顺序结构 顺便提了一下宏和函数的概念 让我对宏和函数有个初步的认识ide
#include <stdio.h> int Max (int x , int y) { if (x>y) return x; else return y; } // 函数 #define MAX(X,Y) (X>Y?X:Y) //宏 int main() { int a = 1; int b = 2; int max=0; max = Max (a,b); printf ("max=%d\n",max); max = MAX (a ,b); printf ("max=%d\n",max); return 0; }
选择结构 函数
#include <stdui.h> int main() { int day = 0; printf ("输入一个数,就能输出对应的周几是否为工做日"); scanf ("%d",&a); switch (day) { case 1 : case 2 : case 3 : case 4 : case 5 : printf ("工做日"); break; case 6; case 7; printf ("休息日"); break; default: printf ("输入错误\n"); break; } return 0; }
循环结构 有for while do while三种类型ui
#include <stdio.h> int main () { int a = 0; while (a<10) { a++; if (5 == a) { continue ; // continue 的做用为跳过本次循环 如下的语句再也不执行 } printf (" %d ",a); } return 0; }