1、c语言中switch语句
将程序分为多个分支的时候,可以使用switch语句。
#include <stdio.h>
int main(void)
{
int i;
puts("please input an integer.");
printf("i = "); scanf("%d", &i);
if (i % 3 == 0)
puts("can be devided by 3");
else if (i % 3 == 1)
puts("the reminder is 1");
else
puts("the reminder is 2");
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i;
puts("please input an integer!");
printf("i = "); scanf("%d", &i);
switch(i % 3)
{
case 0: puts("can be devided by 3"); break;
case 1: puts("the reminder is 1"); break;
case 2: puts("the reminder is 2"); break;
}
return 0;
}