c語(yǔ)言switch語(yǔ)句中break的用法
時(shí)間:
長(zhǎng)思709由 分享
在C語(yǔ)言中break的意思就是執(zhí)行到這一步下面的都不執(zhí)行了。比如從case 1開始執(zhí)行,如果沒break,則下面的語(yǔ)句都會(huì)執(zhí)行,直到遇到下一個(gè)break或者當(dāng)前代碼塊運(yùn)行完畢。下面小編就來(lái)為大家介紹c語(yǔ)言switch語(yǔ)句中break的用法。
#include<stdio.h>intmain(){intge,shi,bai,qian,wan,num,place;
printf("輸入一個(gè)0-99999的正整數(shù):\n");scanf("%d",&num);if(num>9999)place=5;elseif(num>999)place=4;elseif(num>99)place=3;elseif(num>9)
place=2;
elseplace=1;
printf("這個(gè)數(shù)一共%d位。\n",place);wan=num/10000;
qian=(num-wan*10000)/1000;
bai=(num-wan*10000-qian*1000)/100;shi=(num-wan*10000-qian*1000-bai*100)/10;ge=num-wan*10000-qian*1000-bai*100-shi*10;switch(place)
{
case5:printf("萬(wàn)位數(shù)為%d;\n",wan);case4:printf("千位數(shù)為%d;\n",qian);case3:printf("百位數(shù)為%d;\n",bai);case2:printf("十位數(shù)為%d;\n",shi);case1:printf("個(gè)位數(shù)為%d;\n",ge);/*case1:printf("個(gè)位數(shù)為%d;\n",ge);//break;case2:printf("十位數(shù)為%d;\n",shi);//break;case3:printf("百位數(shù)為%d;\n",bai);//break;case4:printf("千位數(shù)為%d;\n",qian);//break;case5:printf("萬(wàn)位數(shù)為%d;\n",wan);*/}
switch(place)
{
case1:printf("反序數(shù)為%d.\n",ge);break;
case2:printf("反序數(shù)為%d%d.\n",ge,shi);break;
case3:printf("反序數(shù)為%d%d%d.\n",ge,shi,bai);break;
case4:printf("反序數(shù)為%d%d%d%d.\n",ge,shi,bai,qian);break;case5:printf("反序數(shù)為%d%d%d%d%d.\n",ge,shi,bai,qian,wan);}return0;
}