|
Post by huangno1 on Feb 25, 2017 6:44:38 GMT -8
程式說明
練習從函式中回傳數值。
題目述
請完成 AskBirthYear() 與 isLeapYear() 函式。
AskBirthYear() 函式會詢問使用者其出生年份,並將該值回傳。
isLeapYear() 有一個傳入的引數,若該引數代表之西元年份為閏年,回傳非 0 值;否則回傳 0 值。
#include <stdio.h>
int AskBirthYear() { int year; printf("When were you born? (Input format: 19xx)...>"); scanf("%d", &year); return year ; } int isLeapYear ( int year ) { if ( ! ( year % 4 ) ) { if ( ! ( year % 100 ) && ( year % 400 ) ) return 0 ; else return 1 ; } else return 0 ; } int main() { if (isLeapYear ( AskBirthYear( ) )) printf("Hey, you were born in a leap year!"); else printf("You were born in a common year."); return 0;
}
|
|