回覆列表
  • 1 # lanfengz3

    1)簡化形式

    if(表示式) 語句塊

    如: if(x>y) printf(“%d”,x);

    2)一般形式

    if (表示式)

    語句塊1

    else

    語句塊2

    例如:

    if (x>y)

    printf(“max=%d”,x);

    else

    printf(“max=%d”,y);

    3)巢狀形式

    含義:一條if語句重又包含另一個if語句稱為if語句的巢狀.

    格式:

    if( )

    if( ) 語句塊1

    else 語句塊2

    else

    if( ) 語句塊3

    else 語句塊4

    例如:

    if (score>90)

    printf(“very good”);

    else

    if(score>80)

    printf(“good”);

    else

    if(score>60)

    printf(“ok”);

    else

    printf(“bad”);

    如果語句塊包含多個語句,用{}就行了

    例如:

    if(n>0)

    {

    printf("%d",n);

    printf("是正數\n");

    }

  • 中秋節和大豐收的關聯?
  • 為什麼聲光控燈只能用白織燈,而不是節能燈?