1、判斷是否為閏年?
程式範例~G:\我的雲端硬碟\c語言練習題\閏年判斷一次條件
//400的倍數 或 (4位倍數且不是100的倍數)才是閏年
#include <stdio.h>
int main(){
int year=0;
printf("輸人西元幾年=");
scanf("%d",&year);
if (year%400==0 || (year%4==0 && year%100!=0) ){
printf("%d年是閏年",year);
}
else{
printf("%d年不是閏年",year);
}
}
測試結果~
輸人西元幾年=1900
1900年不是閏年
------------------------
輸人西元幾年=2000
2000年是閏年
-------------------------------
2、輸入年月日計算是當年的第幾天?
程式範例~G:\我的雲端硬碟\c語言練習題\輸入年月日計算是當年的第幾天
//輸入年月日計算是當年的第幾天
#include <stdio.h>
int main(){
int year=0,mon=0,day=0,leap=0,i=0;
int ans=0;
printf("input year mon day, space分開=");
scanf("%d%d%d",&year,&mon,&day);
if (year%400==0 || (year%4==0 && year%100!=0) ){
leap=1;
}
for (i=1;i<mon;i++){
if (i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12){
ans=ans+31;
}
if (i==4 || i==6 || i==9 || i==11){
ans=ans+30;
}
if (i==2 && leap==1){
ans=ans+29;
}
if (i==2 && leap==0){
ans=ans+28;
}
}
ans=ans+day;
printf("%d年%d月%d日\n是%d年的第%d天\n",year,mon,day,year,ans);
}
測試結果~
input year mon day, space分開=2020 6 14
2020年6月14日
是2020年的第166天
-----------------------------------
input year mon day, space分開=2019 1 5
2019年1月5日
是2019年的第5天
訂閱:
張貼留言 (Atom)
Chrome教學5-建立桌面捷徑1110217
建立桌面捷徑
-
教室佈置 1、創意相框 https://flipedu.parenting.com.tw/article/5229 2、教室佈置水族箱 https://flipedu.parenting.com.tw/article/6093?utm_source=Flipedu.Line&am...
-
1、指標宣告,是存變數的記憶體位置的變數 https://programming.im.ncnu.edu.tw/Chapter9.htm int b ; //跟記憶體要一塊區域稱為b,這塊區域專門放int型變數值 b = 2 ; //把2這個值...
-
「 Google 雲端硬碟檔案串流」消失~解決之道 http://clongwh.blogspot.com/2018/08/GoogleDriveFS.html
沒有留言:
張貼留言