资源描述:
《经典C语言源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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%=7;switch(wee
4、k){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)某年某月某日是第几天(一维数组)#include"stdio.h"voidmain(){inti
5、,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、ear,month,day,dayth);}2、30个数中找最小的数及其位置#include"stdio.h"#defineSIZE30voidmain(){inti;floatdata[SIZE];intmin;printf("请输入%d个浮点数:",SIZE);for(i=0;i9、2f,位置是%5d",data[min],min);}3、30个数从小到大排序(1)#include"stdio.h"#defineSIZE30voidmain(){inti,j;floatdata[SIZE],temp;intmin;printf("请输入%d个整型数:",SIZE);for(i=0;i10、ata[i];data[i]=temp;}printf("排序后的结果是:");for(i=0;i11、前:");show_array(score,SIZE);sort(score,SIZE);..printf("排序后:");show_array(score,SIZE);}voidaccept_array(floata[],intsize){inti;printf("请输入%d个分数:",size);for(i=0;i