switch case 求圖形面積--C語言

switch case 應用舉例 求圖形面積

#include "stdafx.h"

int main(int argc, char* argv[])
{ 
   int tape,b,r,s=0,pi=3;
   printf("請輸入圖形的類型,圓形爲1,正方形爲2,長方形爲3\n");
   scanf_s("%d",&tape);
   switch (tape)
   {
   case 1:
     printf_s ("請輸入圖形的類型,圓形爲1,正方形爲2,長方形爲3\n");
     scanf_s("%d",&r);
	 s=pi*r*r;
	 printf("%d",s);
	 break;
   case 2:
     printf("請輸入正方形的邊長\n");
     scanf_s("%d",&b);
	 s=b*b;
     printf("%d\n",s);
	 break;
   case 3:
     printf("請輸入長方形的長和寬\n");
     scanf_s("%d",&r);
	 scanf_s("%d",&b);
	 s=r*b;
     printf("%d\n",s);
	 break;
   default:
		 printf("不合理的輸入值 \n");
 }
	return 0;
}


 

 
	 

 

發佈了25 篇原創文章 · 獲贊 1 · 訪問量 399
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章