经典C语言源代码1、(1)某年某月某日是星期几#includestdio.hintmain(){intyear,month,day;while(scanf_s(%d%d%d,&year,&month,&day)!=EOF){if(month==1||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(week0){week+=7;}week%=7;switch(week){case1:printf(Monday\n);break;case2:printf(Tuesday\n);break;case3:printf(Wednesday\n);break;case4:printf(Thursday\n);break;case5:printf(Friday\n);break;case6:printf(Saturday\n);break;case0:printf(Sunday\n);break;}}return0;}1、(2)某年某月某日是第几天(一维数组)#includestdio.hvoidmain(){inti,flag,year,month,day,dayth;intmonth_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf(请输入年/月/日:\n);scanf_s(%d/%d/%d,&year,&month,&day);dayth=day;flag=(year%400==0)||(year%4==0&&year%100!=0);if(flag)month_day[2]=29;for(i=1;imonth;i++)dayth=dayth+month_day[i];printf(%d/%d/%d是第%d天\n,year,month,day,dayth);}2、30个数中找最小的数及其位置#includestdio.h#defineSIZE30voidmain(){inti;floatdata[SIZE];intmin;printf(请输入%d个浮点数:\n,SIZE);for(i=0;iSIZE;i++){//scanf_s(%f,&data[i]);data[i]=rand()%30+1;printf(%f、,data[i]);}min=0;for(i=1;iSIZE;i++){if(data[i]data[min])min=i;}printf(最小值是%5.2f,位置是%5d\n,data[min],min);}3、30个数从小到大排序(1)#includestdio.h#defineSIZE30voidmain(){inti,j;floatdata[SIZE],temp;intmin;printf(请输入%d个整型数:\n,SIZE);for(i=0;iSIZE;i++){scanf_s(%f,&data[i]);}for(i=0;iSIZE;i++){min=i;for(j=i+1;jSIZE;j++)if(data[j]data[min])min=j;temp=data[min];data[min]=data[i];data[i]=temp;}printf(\n排序后的结果是:\n);for(i=0;iSIZE;i++)printf(%5.2f,data[i]);}(2)模块化程序(数组名作为函数参数)#includestdio.h#defineSIZE5voidaccept_array(floata[],intsize);voidsort(floata[],intsize);voidshow_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;isize;i++)scanf_s(%f,&a[i]);}voidshow_array(floata[],intsize){inti;for(i=0;isize;i++)printf(%5.2f,a[i]);printf(\n);}voidsort(floata[],intsize){inti,min,j;floattemp;for(i=0;iSIZE;i++){min=i;for(j=i+1;jSIZE;j++)if(a[j]a[min])min=j;temp=a[min];a[min]=a[i];a[i]=temp;}}4、(1)指针加减:#includestdio.h#defineSIZE10voidmain(){inta[SIZE]={1,2,3,4,5,6,7,8,9,10};int*pa,i;pa=&a[0];//pa=a;printf(\n);for(i=0;iSIZE;i++){printf(%d,*pa);//printf(%d,*(pa+1));pa++;}}(2)指针比较:#includestdio.h#defineSIZE10voidmain(){inta[SIZE]={1,2,3,4,5,6,7,8,9,10};int*pa,i;int*qa;pa=qa=&a[0];printf(请输入%d整型数:,SIZE);for(;paqa+SIZE;pa++)scanf_s(%d,pa);for(pa--;qa=pa;pa--)printf(%d,*pa);}5、两字符串相连:#includestdio.h#includestring.hvoidstr_cat(charstr1[],charstr2[]);voidmain(){inti,j;charstr1[160];charstr2[80];printf(请输入第一个字符串:);gets(str1);printf(请输入第二个字符串:);gets(str2);str_cat(str1,str2);puts(str1);}voidstr_cat(charstr1[],charstr2[]){inti,j;i=0;while(str1[i]!='\0')i++;j=0;while(str2[j]!='\0'){str1[i]=str2[j];i++;j++;}str1[i]='\0';}6、二维数组(a,b转置)#includestdio.hvoidmain(){inti,j,b[2][3];inta[3][2]={{1,2},{3,4},{5,6}};for(i=0;i2;i++){for(j=0;j3;j++)b[i][j]=a[j][i];}printf(\na:\n);for(i=0;i3;i++){for(j=0;j2;j++)printf(%5d,a[i][j]);printf(\n);}printf(\nb:\n);for(i=0;i2;i++){for(j=0;j3;j++)printf(%5d,b[i][j]);printf(\n);}}7、输入一个二维数组并输出(指针)#includestdio.hvoidmain(){intx[2][3];inti,j;for(i=0;i2;i++)for(j=0;j3;j++)scanf_s(%d,*(x+i)+j);putchar('\n');for(i=0;i2;i++){for(j=0;j3;j++)printf(%d,*(*(x+i)+j));putchar('\n');}}8、冒泡法排序一个数组#includestdio.h#definesize10voidmaopao(inta[]);voidmain(){inta[10];inti;printf(请输入10个整数:\n);for(i=0;i10;i++)scanf_s(%d,&a[i]);maopao(a);}voidmaopao(inta[]){inti,j,temp;for(i=0;i9;i++){//进行9轮排序for(j=0;j9-i;j++)//每轮进行9-i次交换{if(a[j]a[j+1]){temp=a[j];a[j]=a[j+1];//大的沉底,小的上浮a[j+1]=temp;}}}printf(排序结果:\n);for(i=0;i10;i++)printf(%4d,a[i]);}9、两数组A,B,要求AB,如A:4,7,9B:1,3,5,8,9变换后A:1,3,5B:4,7,8,9,9#includestdio.hvoidReArranger(int*A,int*B,intm,intn)//A和B是各有m个和n个整数的非降序数组,本算法将B数组元素逐个插入到A中,使A中各元素均不大于B中各元素,且两数组仍保持非降序排列。{intx,j,i;while(A[m-1]B[0]){x=A[m-1];A[m-1]=B[0];//交换A[m-1]和B[0]j=1;while(jn&&B[j]x)B[j-1]=B[j++];//寻找A[m-1]的插入位置B[j-1]=x;x=A[m-1];i=m-2;while(i=0&&A[i]x)A[i+1]=A[i--];//寻找B[0]的插入位置A[i+1]=x;}}voidmain()//这里主要介绍算法思想,主函数就简单写了{intA[3],B[5],i;printf(输入第一个数组:);for(i=0;i3;i++){scanf_s(%d,&A[i]);}printf(\n输入第二个数组:);for(i=0;i5;i++){scanf_s(%d,&B[i]);}ReArranger(A,B,3,5);printf(\n输出第一个数组:);for(i=0;i3;i++)printf(%d,A[i]);printf(\n\n);printf(输出第二个数组:);for(i=0;i5;i++)printf(%d,B[i]);printf(\n);}10、符合1+6+3=3+2+5=1+4+5有哪几组A1BC64DEF到325#includestdio.hvoidmain(){inta,b,c,d,e,f;for(a=1;a=6;a++)for(b=1;b=6;b++){if(b==a)continue;for(c=1;c=6;c++){if((c==a)||(c==b))continue;for(d=1;d=6;d++){if((d==a)||(d==b)||(d==c))continue;for(e=1;e=6;e++){if((e==a)||(e==b)||(e==c)||(e==d))continue;f=21-(a+b+c+d+e);if((a+b+d==d+e+f)&&(a+b+d==a+c+f)){printf(%d\n,a);printf(%d%d\n,b,c);printf(%d%d%d\n,d,e,f);}}}}}}11、输入一串字符,升序排序,折半查找其中一字符#includestdio.hvoid*sortString(charunsort[],intlength){for(inti=0;ilength;i++){for(intj=i+1;jlength;j++){if(unsort[i]unsort[j]){inttemp=unsort[j];unsort[j]=unsort[i];unsort[i]=temp;