开始就是简单的顺序结构 选择结构 循环结构 都很容易理解 我现在使用的编译器为 MSVC2019 企业版 顺序结构 顺便提了一下宏和函数的概念 让我对宏和函数有个初步的认识
#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 <stdio.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三种类型
#include <stdio.h>
int main ()
{
int a = 0;
while (a<10)
{
a++;
if (5 == a)
{
continue ; // continue 的作用为跳过本次循环 以下的语句不再执行
}
printf (" %d ",a);
}
return 0;
}