用C语言写一个函数,给出年月日,计算该日是该年的第几天 用#include<iostream,h>开头的 C语言程序设计:给出年、月、日,计算该日是该年的第几天。
\u7528c\u8bed\u8a00\u7f16\u5199\uff1a\u7ed9\u51fa\u5e74\u3001\u6708\u3001\u65e5\uff0c\u8ba1\u7b97\u8be5\u65e5\u662f\u8be5\u5e74\u7684\u7b2c\u51e0\u5929\u3002#include
int main()
{
int n,y,r,t,i;
int a[12];
a[1]=31; a[2]=28; a[3]=31;
a[4]=30; a[5]=31; a[6]=30;
a[7]=31; a[8]=31; a[9]=30;
a[10]=31;a[11]=30;a[12]=31;
while (scanf("%d %d %d",&n,&y,&r)!=EOF)
{
t=0;
if((n%4==0 && n%100!=0)||(n%400==0)) a[2]=29; else a[2]=28;
for (i=1;i<y;i++)
t+=a[i];
t+=r;
printf("%d\n",t);
}
}
#include "stdio.h"
int main () {
int year;
int month;
int day;
scanf("%d %d %d", &year, &month, &day);
if(year 12) || (day 31))return -1;
int daynum[12] = {
31, 28, 31,30 ,31, 30, 31, 31, 30, 31, 30, 31
};
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
daynum[1] = 29;
}
int dayth = 0;
for (int i = 0; i < month - 1; ++i) {
dayth += daynum[i];
}
dayth += day;
printf("the day is:%d\n", dayth);
return 0;
}
代码如下:
#include <iostream>
using namespace std;
int leap_year(int n)
{
if(n%400==0||(n%4==0 && n%100!=0))
return 1;
else
return 0;
}
int main()
{
int year,month,day;
int dayCount=0,i;
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"请输入当前的年,月,日: ";
cin>>year>>month>>day;
for(i=0;i<month-1;i++)
dayCount+=mon[i];
if(month>2)
dayCount+=day+leap_year(year);
else
dayCount+=day;
cout<<"该日是该年的第几天: "<<dayCount<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int year,month,day;
int i,j;
int mon[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"请输入‘年 月 日’:";
cin>>year>>month>>day;
if(year%4==0&&(year%400==0||year%100!=0))//闰年
mon[2]=29;
if(month<1||day<1||month>12||mon[month]<day)
cout<<"日期格式非法!"<<endl;
else{
for(i=1,j=0;i<month;i++)
j += mon[i];
cout<<"这是当年的第 "<<j+day<<" 天!"<<endl;
}
return 0;
}
注意输入年月日中间要用空格。
绛旓細i=1;} } else { if(day>0&&day<=28){ i=1;} } break;default: //濡傛灉杈撳叆涓嶆槸1-12鏈堜唤锛岄偅涔堟湀浠借緭鍏ユ湁璇紱i=0;break;} if(i) //濡傛灉i鍙橀噺涓1锛岄偅涔堣緭鍏ユ纭紝鍚﹀垯閲嶆柊杈撳叆锛泏 break;} else { printf("璇疯緭鍏ユ纭殑骞存湀鏃!!!\n");} }i=0;switch(month) //鎶婃瘡涓湀鐨勬棩鏈...
绛旓細1銆侀鍏堟墦寮vc6.0, 鏂板缓涓涓獀c椤圭洰銆2銆佹坊鍔犲ご鏂囦欢鍜宮ain鍑芥暟銆3銆佸畾涔塪ay銆乵onth銆亂ear銆乻um銆乴eap 浜斾釜鍙橀噺銆4銆佷娇鐢 scanf缁欏畾涔夌殑鍙橀噺璧嬪笺5銆佷娇鐢╯witch璇彞锛屽厛璁$畻鏌愭湀浠ュ墠鐨鏈堜唤鐨勬诲ぉ鏁般6銆佷娇鐢╯um, 鍔犱笂鏌愬ぉ鐨勫ぉ鏁般7銆佸垽鏂槸涓嶆槸闂板勾銆8銆佸鏋滄槸闂板勾涓旀湀浠藉ぇ浜2锛 鎬诲ぉ鏁板簲璇ュ姞涓澶...
绛旓細include <stdio.h> struct DAYS { int year;int month;int day;};int count_days(struct DAYS d){ int ds;switch(d.month){ case 1 :ds=d.day;break;case 2 :ds=31*1+d.day;break;case 3 :ds=31*1+28+d.day;break;case 4 :ds=31*2+28+d.day;break;case 5 :ds=31*2+...
绛旓細),"骞",today.getMonth()+1,"鏈",today.getDate(),"鏃 ","" );document.write("") ;document.write( d[today.getDay()+1],""); 澶嶅埗鍒拌浜嬫湰閲岋紝淇濆瓨涓*.htm鏍煎紡鍙屽嚮鎵撳紑鍗冲彲锛孋璇█灏辨妸document.write鏀逛负printf鍖呭惈鏃ユ湡澶存枃浠讹紝鍐嶅姞涓涓猰ain()鍑芥暟銆
绛旓細include <stdio.h>#include <math.h>int year(int year);int month(int month,int year);void main(){ int y,m,d,sum,i,n; printf("璇疯緭鍏骞存湀鏃\n"); scanf("%d%d%d",&y,&m,&d); y=year(y); sum=0; n=0;//瀹氫箟涓涓猲锛岀敤浜庢瘡涓湀浠藉ぉ鏁扮浉鍔 for(i=1;i<m;i++) { ...
绛旓細{return year % 400 == 0 || (year % 100 && year % 4 == 0);}int DateDistace(Date a, Date b){if (DateCmp(a, b))//淇濊瘉a灏忎簬b{Date t = b;b = a;a = t;}//璁$畻缁撴灉瀛樺偍鍦╮es涓//棣栧厛璁$畻鐩稿樊鐨勫勾int i = a.year + 1, j = b.year - 1, res = a....
绛旓細= {31,28,31,30,31,30,31,31,30,31,30,31}; if(year(a)==1) n[1] = 29; int b; for(b = 0;b<y-1;b++) // 鏈堜唤鍑 1 锛屽洜涓烘暟缁勬槸 0 寮濮嬬殑 { sum+=n[b]; } return sum;}main(){ int b,c,d; scanf("%d,%d,%d",&a,&b,&c); d = month(b)...
绛旓細include <stdio.h> struct date //瀹氫箟缁撴瀯浣撶被鍨 { int y;int m;int d;};void main(){ date dt; //瀹氫箟缁撴瀯浣撳彉閲 int i,count, mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf("璇疯緭鍏ユ棩鏈燂紙骞 鏈 鏃锛夛細");scanf("%d",&dt.y);scanf("%d",&dt.m)...
绛旓細if(leap(year)==1)for(i=0;i<=m-2;i++)sum+=b[i];else for(i=0;i<=m-2;i++)sum+=a[i];sum+=d;return (sum);} void main(){ int year,m,d,n;printf("璇疯緭鍏骞存湀鏃\n");scanf("%d,%d,%d",&year,&m,&d);leap(year);n=number(year,m,d);printf("di %d ...
绛旓細int isLeapYear(int year){ return year%4==0&&year%100!=0||year%400=0;} int day_of_year(int year, int month, int day){ const int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};int i,s=day;for(i=0;i<month-1;i++)s+=m[i];if(isLeapYear(year))s++;return...