判别闰年#includestdio.hintmain(){intyear;printf(请输入年份:);scanf(%d,&year);if(year%100==0)if(year%400==0)printf(此年是闰年\n);elseprintf(此年不是闰年);elseif(year%4==0)printf(此年是闰年);elseprintf(此年不是闰年);return0;}百分制成绩与等级制成绩互相转换#includestdio.hintmain(){chargrade;floatscore;printf(请输入成绩);scanf(%f,&score);while(score100||score0){printf(输入错误请从新输入);scanf(%f,&score);}switch(int(score/10)){case10:case9:printf(A\n);break;case8:printf(B\n);break;case7:printf(C\n);break;case6:printf(D\n);break;default:printf(E\n);}}大小写字母转换#includestdio.hvoidmain(){charc1,c2;scanf(%c,&c1);c2=c1+32;printf(%c,c2);}加法器累乘器#includestdio.hmain(){inta,b;printf(pleaseinputnumber1:\n);scanf(%d,&a);printf(pleaseinputnumber2:\n);scanf(%d,&b);printf(number1addnumber2is%d\n,a+b);}#includestdio.hintmain(){inti;intp=1;for(i=2;i=10;i++){p=p*i;}printf(%d.\n,p);return0;}最大数最小数#includestdio.hintmain(){inta,b,c,max,min;printf(输入3个数:\n);scanf(%d%d%d,&a,&b,&c);max=a;if(maxb)max=b;if(maxc)max=c;min=a;if(minb)min=b;if(minc)min=c;printf(最大值:%d,最小值:%d\n,max,min);}冒泡排序和选择排序#includestdio.hintmain(){inti,j,t;inta[10];printf(input10number:\n);for(i=0;i10;i++)scanf(%d,&a[i]);for(j=0;j=9;j++){for(i=0;i10-j;i++)if(a[i]a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}for(i=0;i10;i++)printf(%5d,,a[i]);printf(\n);}#includestdio.h#includestdlib.h#defineN8voidselect_sort(inta[],intn);//选择排序实现voidselect_sort(inta[],intn)//n为数组a的元素个数{//进行N-1轮选择for(inti=0;in-1;i++){intmin_index=i;//找出第i小的数所在的位置for(intj=i+1;jn;j++){if(a[j]a[min_index]){min_index=j;}}//将第i小的数,放在第i个位置;如果刚好,就不用交换if(i!=min_index){inttemp=a[i];a[i]=a[min_index];a[min_index]=temp;}}}intmain(){intnum[N]={89,38,11,78,96,44,19,25};select_sort(num,N);for(inti=0;iN;i++)printf(%d,num[i]);printf(\n);system(pause);return0;}判别键盘输入类型#includestdio.hvoidmain(){charch;printf(请输入一个字符:\n);ch=getchar();if(ch='a'&&ch'z'||ch='A'&&ch='Z')printf(该字符是字母);elseif(ch='0'&&ch='9')printf(该字符是数字);elseprintf(该字符是特殊字符);}最大公约数和最小公倍数#includestdio.hintmain(){intp,r,m,n,temp;printf(请输入两个正整数);scanf(%d,%d,&n,&m);if(nm){temp=m;n=m;m=temp;}p=m*n;while(m!=0){r=n%m;n=m;m=r;}printf(最大公约数是%d\n,n);printf(最小公倍数是%d\n,p/n);}求菲比拉契数列有限项#includestdio.hintmain(){intf1=1,f2=1,f3;inti;printf(%12d\n%12d\n,f1,f2);for(i=1;i=38;i++){f3=f1+f2;printf(%12d\n,f3);f1=f2;f2=f3;}}验证哥德巴赫猜想#includestdio.hvoidmain(){intx,y,z;inti,j;for(x=4;x100;x++,x++)//对100以内的偶数for(y=1;yx;y++)//yx改成yx/2就可以去掉8=3+58=5+3这类的重复了{for(i=2;iy;i++)//判断y是否为素数if(y%i==0)break;if(i==y)//y是素数{z=x-y;//x=y+zfor(j=2;j=z;j++)//判断z是否为素数if(z%j==0)break;if(j==z)//z是素数printf(%d=%d+%d\t,x,y,z);}}printf(\n);}字符统计#includestdio.hmain(){charch;intchar_num=0,kongge_num=0,int_num=0,other_num=0;while((ch=getchar())!='\n'){if(ch='a'&&ch='z'||ch='z'&&ch='a'){char_num++;}elseif(ch==''){kongge_num++;}elseif(ch='0'&&ch='9'){int_num++;}else{other_num++;}}printf(字母=%d,空格=%d,数字=%d,其它=%d\n,char_num,kongge_num,int_num,other_num);return0;}统计学生成绩#includestdio.hmain(){doublegrade[200];doublesum,avg,temp;intcount,i,n;i=0;count=0;sum=0;printf(请依次输入每个同学的成绩,输入-1结束\n);scanf(%lf,&temp);while(temp!=-1){grade[i++]=temp;count++;sum=sum+temp;scanf(%lf,&temp);}avg=sum/count;n=0;for(i=0;icount;i++){if(grade[i]=avg)n++;}printf(全班平均分%.2lf,成绩大于等于平均分的人有%d人\n,avg,n);}素数#includestdio.h#includemath.hintmain(void){inti,s,k,count=0;for(i=100;i=200;i++){k=sqrt(i);for(s=2;s=k;s++){if(i%s==0)break;}if(s==k+1)count++;}printf(%d\n,count);for(i=100;i=200;i++){k=sqrt(i);for(s=2;s=k;s++){if(i%s==0)break;}if(s==k+1)printf(%d,i);}return0;}水仙花数和完全平方数#includestdio.hvoidmain(){inti,j,k,n;printf(水仙花数:\n);for(n=100;n1000;n++){i=n/100;j=(n-i*100)/10;k=n%10;if(i*i*i+j*j*j+k*k*k==n){printf(%d,n);}}}#includestdio.h#includemath.hvoidmain(){inti,j,cnt=0;for(i=1;i=1000;i++){for(j=1;j=sqrt(i);j++)if(i==j*j){printf(%d,,i);cnt++;if(cnt%8==0)printf(\n);}elsecontinue;}}