资源描述:
《经典C语言源代码.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、;.经典C语言源代码1、(1)某年某月某日是星期几#includeintmain(){intyear,month,day;while(scanf_s("%d%d%d",&year,&month,&day)!=EOF){if(month==1
2、
3、month==2)//判断month是否为1或2{year--;month+=12;}intc=year/100;inty=year-c*100;intweek=(c/4)-2*c+(y+y/4)+(13*(month+1)/5)+day-1;while(week<0){week+=7;}week%
4、=7;switch(week){case1:printf("Monday");break;;.';.case2:printf("Tuesday");break;case3:printf("Wednesday");break;case4:printf("Thursday");break;case5:printf("Friday");break;case6:printf("Saturday");break;case0:printf("Sunday");break;}}return0;}1、(2)某年某月某日是第几天(一维数组)#in
5、clude"stdio.h"voidmain(){inti,flag,year,month,day,dayth;intmonth_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf("请输入年/月/日:");scanf_s("%d/%d/%d",&year,&month,&day);dayth=day;flag=(year%400==0)
6、
7、(year%4==0&&year%100!=0);if(flag)month_day[2]=29;;.';.for(i=1;i8、dayth+month_day[i];printf("%d/%d/%d是第%d天",year,month,day,dayth);}2、30个数中找最小的数及其位置#include"stdio.h"#defineSIZE30voidmain(){inti;floatdata[SIZE];intmin;printf("请输入%d个浮点数:",SIZE);for(i=0;i9、;i10、r(j=i+1;j11、ow_array(floata[],intsize);voidmain(){floatscore[SIZE];accept_array(score,SIZE);printf("排序前:");show_array(score,SIZE);sort(score,SIZE);;.';.printf("排序后:");show_array(score,SIZE);}voidaccept_array(floata[],intsize){inti;printf("请输入%d个分数:",size);for(i=0;i12、);}voidshow_array(floata[],intsiz