1. 程式人生 > 實用技巧 >C語言成長之路29:if else實現求偶程式

C語言成長之路29:if else實現求偶程式

if-else 語句

順序結構:程式從Main函式進入從上到下一行一行的執行,不會落下任何一行;

1、if語句

1     if (判斷條件,需要為真才會執行){
2         dosomething;
3     }

注:if裡面的一般會使用關係表示式進行判斷;

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <limits.h>
 4 #include <Windows.h>    //呼叫Windows標頭檔案
 5 
 6 void main(){
 7     /*
C語言成長之路29:if else實現求偶程式 8 * 9 */ 10 printf("Hello\n"); 11 printf("1:yes;\n2:no\n3:dont care;\n"); 12 int i = 0; 13 int num; 14 scanf("%d",&num); 15 if (num == 1){ 16 printf("yes\n"); 17 } else if (num == 2){ 18 printf("no\n"); 19 } else if
(num == 3){ 20 printf("dont care"); 21 } else { 22 while (i < 5){ 23 MessageBox(0,"Fuck off!","go home",1); // 這裡就控制了亂輸入以後的一個操作,因為不是多執行緒,只能一個一個彈出來 24 i++; 25 } 26 } 27 };

MessageBox函式說明:

MessageBox函式中包含4個引數

第一個引數0表示系統呼叫;

第二個引數表示彈出框的展示內容;

第三個引數表示彈出框的標題內容;

第四個引數表示彈出框的選項樣式;