c語言全年
『壹』 C語言日歷
#include <stdio.h>
typedef struct date
{
int year;
int month;
int day;
}DATE;
int main()
{
DATE your_date;
your_date.month=1;
your_date.day=1;
printf("please putin your date.\n");
printf("year:\n");
scanf("%d",&your_date.year);
int a,b,c;
a=your_date.year-2000;
b=a*365+a/4-a/100+a/400;
c=b%7;
int m;
int d;
int w=(c+6)%7;
for(m=1;m<=12;m++){
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){
for(d=1;d<=31;d++){
printf("year:%d,month:%d,date:%d,week:%d\n",your_date.year,m,d,w);
w=(w+1)%7;
}
}else {
for(d=1;d<=30;d++){
printf("year:%d,month:%d,date:%d,week:%d\n",your_date.year,m,d,w);
w=(w+1)%7;
}
}
}
return 0;
}
『貳』 用C語言編寫程序列印任意年份的日歷
#include <stdio.h>
int JgYr(int yr)
{
if (yr%4==0&&yr%100!=0||yr%100==0&&yr%400==0)
return 1;
else
return 0;
}
int CalWkd(int yr,int mth)
{
int ds=0,i,rst,wkd;
int mthd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (JgYr(yr))
mthd[2]=29;
for (i=1;i<mth;i++)
ds+=mthd[i];
ds+=1;
rst=yr-1+(int)((yr-1)/4)-(int)((yr-1)/100)+(int)((yr-1)/400)+ds;
wkd=rst%7;
return wkd;
}
showcld(int wkd,int mtd)
{
int dt=1,i,j=0;
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");
for (i=0;i<wkd;i++)
{
printf("\t");
j++;
}
while (j!=7)
{
printf("%d",dt);
if (j<6)
printf("\t");
else
printf("\n");
dt++;
j++;
}
while (1)
{
for (j=0;j<7;j++)
{
printf("%d",dt);
if (j!=6)
printf("\t");
else
printf("\n");
if (dt!=mtd)
dt++;
else
return 0;
}
}
}
int main()
{
int yr,mth,mtd,wkd,mthd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("Input the Year and Month(Year-Month):");
scanf("%d-%d",&yr,&mth);
if (yr<0||mth<1||mth>12)
return 0;
if (JgYr(yr))
mthd[2]=29;
mtd=mthd[mth];
wkd=CalWkd(yr,mth);
showcld(wkd,mtd);
return 0;
}
『叄』 C語言編程輸入某單位全年應納所得額數目,計算並輸出應繳稅額和實際所得
你看我的理解對不。如果有問題,HI我。
/*表達的有點不清楚,如果x是20000,按10%算還是按20%算*/
#include<stdio.h>
int main(void)
{
double tax=0,money,m;
int c;
printf("請輸入全年應納所得額數目:\n");
scanf("%lf",&money);
m=money;
if(money/10000>8)
c=8;
else
c=(int)money/10000;
switch(c)//找到一個入口,順次相加各個級應納稅額。
{
case 8:tax+=(money-80000)*0.35;money=80000;
case 7:
case 6:
case 5:
case 4:tax+=(money-40000)*0.30;money=40000;
case 3:
case 2:tax+=(money-20000)*0.20;money=20000;
case 1:tax+=(money-10000)*0.10;money=10000;
case 0:tax+=money*0.05;break;
default:printf("Data Error!\n");
}
printf("應納稅額:%.2f\n",tax);
printf("最終所得:%.2f\n",m-tax);
return 0;
}
為了便於你驗證程序執行結果:下面的可以多次執行,直到你輸入的money不大於0.
#include<stdio.h>
int main(void)
{
while(1)
{
double tax=0,money,m;
int c;
printf("請輸入全年應納所得額數目:\n");
scanf("%lf",&money);
if(money<=0)
break;
m=money;
if(money/10000>8)
c=8;
else
c=(int)money/10000;
switch(c)//找到一個入口,順次相加各個級應納稅額。
{
case 8:tax+=(money-80000)*0.35;money=80000;
case 7:
case 6:
case 5:
case 4:tax+=(money-40000)*0.30;money=40000;
case 3:
case 2:tax+=(money-20000)*0.20;money=20000;
case 1:tax+=(money-10000)*0.10;money=10000;
case 0:tax+=money*0.05;break;
default:printf("Data Error!\n");
}
printf("應納稅額:%.2f\n",tax);
printf("最終所得:%.2f\n",m-tax);
}
return 0;
}
『肆』 C語言年歷顯示程序設計
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
char* month[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nev","Dec"};
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int j_leapyear(int year) //定義函數檢測輸入年份是否為閏年
{
if((/*year%400==0*/year%4==0&&year%100!=0)||(year%400==0))
return (1);
// else if(year%4==0&&year%100!=0)
// return (1);
else return 0;
}
int month_day(int year,int month) //檢測該年月份有多少天
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(j_leapyear(year)&&month==2)
return 29;
else return (mon_day[month-1]);
}
int j_week(int year,int month,int day) //檢測該天是星期幾
{
int d=0,i; //d表示該天在該年份的累計天數
int w;
/* int month_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(j_leapyear(year)==1)
month_day[1]=29;
for(i=0;i<month;i++)
d+=month_day[i];
d=d+day;*/
for(i=1;i<month;i++)
d+=month_day(year,i);
d+=day;
w=(year-1)+(int)(year-1)/4-(int)(year-1)/100+(int)(year-1)/400+d;//網上公式
return ((int)w%7);
}
int allyear(int year) //輸出全年日歷
{
int i,j,b;
printf("\n%d 日歷",year);
for(i=1;i<=12;i++)
{
printf("\n\n\t%s\n",month[i-1]);
// printf(" 7 1 2 3 4 5 6 \n");
printf(" S M T W T F S \n");
b=j_week(year,i,1);
for(j=1;j<=month_day(year,i)+b;j++)
{
if(j<=b)
printf(" ");
else if(j-b<10)
printf("%2d ",j-b);
else printf("%2d ",j-b);
//else printf("%2d ",j-b);
if(j%7==0)
putchar('\n');
}
putchar('\n');
}
return 0;
}
void month_print(int year,int month) //輸入一個年月,輸出這個月的日歷
{
int i,c,d;
c=month_day(year,month);
printf("\n\n %d年%d月日歷\n",year,month);
printf(" S M T W T F S \n");
d=j_week(year,month,1);
for(i=1;i<=c+d;i++)
{
if(i<=d)
printf(" ");
else printf("%2d ",i-d);
if(i%7==0)
putchar('\n');
}
putchar('\n');
}
int jisuan_day(int year,int month,int day,int x,int y,int z) //輸入年月日,輸出距x年y月z日有多少天,星期幾,以及是否是公歷節日
{
int i,a,b,c=0,d=0,days=0,m=0,n=0,t;
a=year>=x?year:x;
b=year<x?year:x;
if(a>b)
{
for(i=b+1;i<a;i++)
c+=j_leapyear(i);
}
else c=0;
if(year!=x)
d=a-b-1;
else d=0;
m=365*d+c;
if(year<x)
{
for(i=month;i<=12;i++)
n+=month_day(year,i);
days=m+n+z-day;
}
else if(year>x)
{
for(i=y;i<=12;i++)
n+=month_day(x,i);
for(i=1;i<month;i++)
n+=month_day(year,i);
days=m+n+day-z;
}
else
{
for(i=month>=y?y:month;i<(month>=y?month:y);i++)
n+=month_day(x,i);
days=abs(day-z)+n; //輸出距離y月z日有多少天
}
printf("這天離%d年%d月%d號有%d天\n",x,y,z,days);
t=j_week(year,month,day);
if(t==0) //輸出星期幾
printf("這天星期日");
else if(t==1)
printf("這天星期一");
else if(t==2)
printf("這天星期二");
else if(t==3)
printf("這天星期三");
else if(t==4)
printf("這天星期四");
else if(t==5)
printf("這天星期五");
else if(t==6)
printf("這天星期六");
putchar('\n');
if(month==1&&day==1)
printf("這天是元旦節");
else if(month==2&&day==14)
printf("這天是情人節");
else if(month==3&&day==8)
printf("這天是婦女節");
else if(month==3&&day==12)
printf("這天是植樹節");
else if(month==4&&day==1)
printf("這天是愚人節");
else if(month==4&&day==4)
printf("這天是清明節");
else if(month==5&&day==1)
printf("這天是勞動節");
else if(month==6&&day==1)
printf("這天是兒童節");
else if(month==8&&day==1)
printf("這天是建軍節");
else if(month==9&&day==10)
printf("這天是教師節");
else if(month==10&&day==1)
printf("這天是國慶節");
else if(month==12&&day==25)
printf("這天是聖誕節");
else printf("這天不是特殊節日");
putchar('\n');
return days;
}
void fish_or_net(int year,int month,int day) //判斷是打魚還是曬網
{
int q;
int i,a,b,c=0,d=0,days=0,m=0,n=0;
a=year>=1990?year:1990;
b=year<1990?year:1990;
if(a>b)
{
for(i=b+1;i<a;i++)
c+=j_leapyear(i);
}
else c=0;
if(year!=1990)
d=a-b-1;
else d=0;
m=365*d+c;
if(year<1990)
{
for(i=month;i<=12;i++)
n+=month_day(year,i);
days=m+n+1-day;
}
else if(year>1990)
{
for(i=1;i<=12;i++)
n+=month_day(1990,i);
for(i=1;i<month;i++)
n+=month_day(year,i);
days=m+n+day-1;
}
else
{
for(i=month>=1?1:month;i<(month>=1?month:1);i++)
n+=month_day(1990,i);
days=abs(day-1)+n; //先確定這天離1990年1月1日有多少天
}
q=days%5+1;
if(q==1||q==2||q==3) //判斷打魚還是曬網
printf("漁人今天打魚");
else printf("漁人今天曬網");
putchar('\n');
}
/*int main() //這部分內容用來校檢
{
int j_leapyear(int year);
int month_day(int year,int month);
int j_week(int year,int month,int day);
int allyear(int year);
void month_print(int year,int month);
int jisuan_day(int year,int month,int day,int x,int y,int z);
void fish_or_net(int year,int month,int day);
int x,y,z,year,month,day;
// allyear(2015);
//month_print(2016,12);
printf("請輸入今天的日期(按年,月,日輸入,如2016,1,14表示2016年1月14日):");
scanf("%d,%d,%d",&x,&y,&z);
printf("\n請隨便輸入一個日期,格式同上:");
scanf("%d,%d,%d",&year,&month,&day);
jisuan_day(year,month,day,x,y,z);
// fish_or_net(x,y,z);
return 0;
} // 這部分內容是用來檢測上述函數是否出錯的
*/
int main()
{
int j_leapyear(int year);
int month_day(int year,int month);
int j_week(int year,int month,int day);
int allyear(int year);
void month_print(int year,int month);
int jisuan_day(int year,int month,int day,int x,int y,int z);
void fish_or_net(int year,int month,int day); //函數聲明
int option,year,month,day,x,y,z;
char ny;
system("color 1f");
while (1)
{
printf("\n\n\t 歡迎來到由...編寫的程序\n\n");
printf(" 請選擇您需要的服務,輸入編號回車結束\n");
printf(" 1.輸入一個年份,輸出該年的日歷\n");
printf(" 2.輸入年月,輸出這個月的日歷。\n");
printf(" 3.輸入年月日,輸出據今天還有多久,星期幾,是否是公歷節日。\n");
printf(" 4.某人自1990年1月1日開始打魚,「三天打魚,兩天曬網」,輸入一個1990年以後的日期,輸出他這一天是打魚還是曬網。\n");
printf(" 5.退出\n");
scanf("%d",&option);
switch(option) //switch分支結構
{
case 1:
while(1) //while循環,後面的1是常數,表示一直到break才結束循環
{
printf("請輸入一個年份:");
scanf("%d",&year);
allyear(year);
printf("你想繼續查詢日歷么?(y表示繼續,n表示結束)");
scanf("%c",&ny);
if(ny=='n')
break;
}
break;
case 2:
while (1)
{
printf("輸入年月:");
scanf("%d,%d",&year,&month);
month_print(year,month);
printf("你想繼續查詢日歷么?(y表示繼續,n表示結束):");
scanf("%c",&ny);
if(ny=='n')
break;
}
break;
case 3:
while (1)
{
printf("輸入年月日:");
scanf("%d,%d,%d",&year,&month,&day);
printf("請輸入今天的日期:");
scanf("%d,%d,%d",&x,&y,&z);
jisuan_day(year,month,day,x,y,z);
printf("你想繼續查詢么?(y表示繼續,n表示結束):");
scanf("%c",&ny);
if(ny=='n')
break;
}
break;
case 4:
while (1)
{
printf("輸入1990年1月1日以後的一個日期:");
scanf("%d,%d,%d",&year,&month,&day);
fish_or_net(year,month,day);
printf("你想繼續查詢漁人是打魚還是曬網么?(y表示繼續,n表示結束):");
scanf("%c",&ny);
if(ny=='n')
break;
}
break;
case 5:
while (1)
{
printf("確認么?y表示是的,n表示不是");
scanf("%c",&ny);
if(ny=='y')
exit(1); //表示退出程序
else if(ny=='n')
break;
}
break;
default:printf("對不起,暫時沒有這個服務");
break;
}
}
return 0;
}