c語言中switch語句
阿新 • • 發佈:2021-01-07
1、
#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");
else
{
if (i % 3 == 1)
puts("remainder is 1.");
else
puts( "remainder 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."); break;
case 1 : puts("remainder is 1."); break ;
case 2 : puts("remainder is 2."); break;
}
return 0;
}
2、
#include <stdio.h>
int main(void)
{
int i;
puts("please input an integer.");
printf("i = "); scanf("%d", &i);
switch (i)
{
case 1 : puts("a"); puts("b"); break;
case 2 : puts(" c");
case 3 : puts("d"); break;
case 4 : ; break;
case 5 : puts("e"); break;
case 6 :
case 7 : puts("f"); break;
default : puts("g"); break;
}
return 0;
}