1. 程式人生 > >C語言期末複習:輸入年月日,求今年已過去多少天

C語言期末複習:輸入年月日,求今年已過去多少天

題目:輸入年月日,輸出今年已經過了多少天了

程式碼:

#include <stdio.h>

#include <stdlib.h>
int pd(int year)
{
if((year % 4==0 && year %100 !=0)||(year %400==0))
return 1;
else return 0;

}  //用來判斷這一年是否是閏年


int main()
{
int year,month,day,sum,i;
int md[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
sum=0;
printf("please input the year,month,day\n");
scanf("%d%d%d",&year,&month,&day);

if(month<=0||month>12||day<=0||day>md[month])

{
printf("輸入出錯");
exit(1);

if(pd(year)==1)
md[2]=29;
for(i=1;i<month;i++)
sum=sum+md[i];

sum=sum+day;

printf("the result is:%d",sum);

return 0;

}

相關推薦

C語言期末複習輸入年月日今年過去多少

題目:輸入年月日,輸出今年已經過了多少天了 程式碼: #include <stdio.h> #include <stdlib.h> int pd(int year) {if((year % 4==0 && year %100 !=0)

大一上C語言期末複習 輸入三角形三條邊長周長和麵積。注意要保證3邊能構成三角形

題目: 輸入三角形三條邊長,求周長和麵積。注意要保證3邊能構成三角形 計算三角形面積的海倫公式:S=√[p(p-a)(p-b)(p-c)]     (其中p為半周長)  #include <stdio.h> #include <math.h> #i

大一上C語言期末複習輸入一個正整數將其分解為質因數如90=2*3*3*5

//輸入一個正整數,將其分解為質因數,如90=2*3*3*5 #include <stdio.h> int main() { int n,i; while(scanf("%d",&n)) { if(n==1) { printf("n=

大一上C語言期末複習猜價格遊戲(隨機生成100以內的整數提示高/低/正確10次未猜準判輸)

題目: 猜價格遊戲(隨機生成100以內的整數,提示高/低/正確,10次未猜準判輸)程式碼:#include<stdio.h> #include<time.h> #include<stdlib.h> int main() { i

大一C語言初學者期末考試複習輸入判斷是否閏年

題目: 輸入年,判斷是否閏年 閏年判斷條件:1、能被4整除且不能被100整除  2、能被400整除  (二者滿足其一即可) #include <stdio.h> int main() {int n;printf("please input the year\n"

C語言經典演算法輸入某年某月某日判斷這一是這一年的第幾

題目:輸入某年某月某日,判斷這一天是這一年的第幾天?1.程式分析:以3月5日為例,應該先把前兩個月的加起來,然後再加上5天即本年的第幾天,特殊      情況,閏年且輸入月份大於3時需考慮多加一天。2.程式原始碼:main(){int day,month,year,sum,l

c語言 用scanf函式輸入資料舉例並分析錯誤原因

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

C語言連結串列遍歷頭插尾插中間插入;頭節點刪除尾節點刪除中間刪除的操作

/****************************************************************************************************************************************

C語言中為什麼scanf輸入語句要在變數名前加&呢?

首先在C語言中,輸入變數的語法是:scanf("格式控制","變數地址") 可以看出,第二個的格式為變數地址。 在C語言中,變數在定義之後,就會在計算機記憶體中非配一塊空間給這個變數,該空間在記憶體中

課堂測試輸入整數出各位數字的和

option system dia int 整數 != tdi n) .cn import javax.swing.JOptionPane;public class Add { public static void main(String[] args) { Str

C語言輸入naSn=a+aa+aaa+···+a···

C語言:輸入n,a,求Sn=a+aa+aaa+···+a···a #include<stdio.h> int main() { int n, a, Sn = 0, t = 0; printf("請輸入n:"); scanf("%d",&n);

輸入年月日輸出是這一年的第幾c語言程式

做為一個學c語言的新手,今天學習了switch語句。當時老師說case語句後面如果不跟break;會按照順序執行,而這種結構也有它的優點,通過今天對這個程式的編寫,也對switch有了全新的認識; /* 請分別輸入年月日三個數值,計算出這是這一年的第幾天? (提示:要考慮閏

初學者C語言問題輸入年月日得到天數

#include<stdio.h> typedef struct {int year;int month;int day; }Date; int LeapYear(int year){if ((year % 4 == 0 && year % 10

C語言來實現_輸入一個日期(年月日)計算是這一年中的第幾

1.環境: 2.程式碼: /*  *wuxiuwen  *input date, the date of this year is calculated which day.  *輸入一個日期(年月日),計算是這一年中的第幾天   */ #include<stdio.

c語言輸入年月日輸出該日為該年中的第多少

#include <stdio.h>int main(){int year=0;int mouth=0;int day=0;int sun=0;printf("請輸入年月日");scanf("%d %d %d",&year,&mouth,&

大一C語言初學者的期末複習m!+n!的和用函式long fact(int m)

題目: 求m!+n!的和:用函式long fact(int m) 簡單的水題,遞迴實現 #include <stdio.h> long fact(int m) {if(m==1||m==0) return 1;else return m*fact(m-1); }

C語言 鍵盤輸入年月日計算該年第幾

設計程式,從 鍵盤輸入年月日三個變數year,month,day,計算該日是該年第幾天 #include<stdio.h> int main() { int year, month, day,n,i,sum=0; scanf("%d,%d,%d", &

c語言寫一個函式輸入n斐波拉契數列的第n項(5種方法層層優化)

寫一個函式,輸入n,求斐波拉契數列的第n項。斐波拉契數列:1,1,2,3,5,8...,當n大於等於3時,後一項為前面兩項之和。解:方法1:從斐波拉契數列的函式定義角度程式設計#include<stdio.h>int fibonacci(int n){int nu

c語言 輸入年月日輸出它是本年第幾

#include <stdio.h> int main() { int year,month,day;//年月日 int i; int sum = 0;//標記天數