c语言

共 59 篇文章

摄氏温度——华氏温度对照表

摄氏温度——华氏温度对照表

/* 功能:摄氏温度——华氏温度对照表 日期:2013-05-08 */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int C; double F; printf(“摄氏温度 华氏温度n”); C = 0; F = C; do { F = (double)C * 9 / 5 + 32.0; printf(“%d %.2lfnn”,C,F); C += 5; }while(C <= 100); printf(“n”); system(“pause”); return 0; }

计算1*2*3+3*4*5+...99*100*101的值

计算1*2*3+3*4*5+...99*100*101的值

/* 功能:计算1*2*3+3*4*5+…99*100*101的值 日期:2013-05-08 */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int Sum,sum1,sum2,sum3; for (sum1 = 1,sum2 = 2,sum3 = 3,Sum=0;sum3 <= 101;sum1 += 2,sum2 += 2,sum3 += 2) { Sum += sum1 * sum2 * sum3; } printf(“1*2*3+3*4*5+…99*100*101的值为:%dn”,Sum); system(“pause”); return 0; }

求和

求和

1-101基数求和/*功能:求和作者:windCoder日期:2013-05-08*/#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#includ

求小球运动路径

求小球运动路径

/* 功能:求小球运动路径 日期:2013-4-19 */ #include <stdio.h> #include <stdlib.h> int main(void) { int n; double hight,s; for (hight=100.0,s=0,n=1;n<=10;n++) { hight=hight/2.0; printf(“第%d次反弹的高度:%.6lfn”,n,hight); s=s+hight; } s=s+100.0; printf(“小球共经过的路程:%.6lfn”,s); system (“pause”); return 0; }

计算平均分

计算平均分

/* 功能:计算平均分 日期:2013-04-01 */ #include<stdio.h> #include<stdlib.h> #include<math.h> int main(void) { double one,two,three,four,five,max,min,average; printf(“请输入5位评委所打的成绩:”); scanf(“%lf,%lf,%lf,%lf,%lf”,&one,&two,&three,&four,&five); max = min = one //求最大值 max = max>two?max; max = max>three?max; max = max>four?max; max = max>five?max; //求最小值 min = min<two?min; min = min<three?min; min = min<four?min; min = min<five?min; //求平均值 average =(one + two + three + four + five - max - min) / 3; printf(“该选手的平均得分是:%.1lfn”,average); system(“pause”); return 0; } ______________________________________________________________________________

字符加密

字符加密

/* 功能:字符加密 日期:2013-04-01 */ #include<stdio.h> #include<stdlib.h> #include<math.h> int main(void) { char One,Two,Three,Four,Five; printf(“请输入5个字符:”); scanf(“%c%c%c%c%c”,&One,&Two,&Three,&Four,&Five); if (One>=97&&One<=122)//第一个字符 { One=( One + 4 - 97 ) % 26 + ‘a’; } if(One>=65&&One<=90) { One=( One + 4 - 65 ) % 26 + ‘A’; } if (Two>=97&&Two<=122)//第二个字符 { Two=(Two + 4 - 97 ) % 26+‘a’; } if (Two>=65&&Two<=90) { Two=(Two + 4 -65 ) % 26 + ‘A’; } if (Three>=97&&Three<=122)//第三个字符 { Three=( Three + 4 - 97 ) % 26 + ‘a’; } if (Three>=65&&Three<=90) { Three=(Three + 4 - 65 ) % 26 + ‘A’; } if (Four>=97&&Four<=122)//第四个字符 { Four=( Four + 4 - 97 ) % 26 + ‘a’; } if ( Four>=65&&Four<=90) { Four=(Four + 4 - 65 ) % 26 + ‘A’; } if ( Five>=97&&Five<=122)//第五个字符 { Five=( Five + 4 - 97 ) % 26 + ‘a’; } if (Five>=65&&Five<=90) { Five=( Five + 4 - 65 ) % 26 + ‘A’; } printf(“加密后的数值是:%c%c%c%c%cn”,One,Two,Three,Four,Five); system(“pause”); return 0; }

数字探秘-统计所输入的字符X的二进制表示中含有多少个1

数字探秘-统计所输入的字符X的二进制表示中含有多少个1

方法一: /* 功能:数字探秘——统计所输入的字符X的二进制表示中含有多少个1 日期:2013-04-01 */ #include<stdio.h> #include<stdlib.h> #include<math.h> int main(void) { char cH1,cH2; printf(“请输入一个字符:”); scanf(“%c”,&cH1); cH2 = cH1; cH1 = (cH1 & 0x5555) + ((cH1>>1) & 0x5555); cH1 = (cH1 & 0x3333) + ((cH1>>2) & 0x3333); cH1 = (cH1 & 0x0F0F) + ((cH1>>4) & 0x0F0F); printf(“字符’%c’的二进制表示中含有%d个1n”,cH2,cH1); system(“pause”); return 0; } ______________________________________________________________________________ 方法二: /* 功能:数字探秘——统计所输入的字符X的二进制表示中含有多少个1 日期:2013-04-01 */ #include<stdio.h> #include<stdlib.h> #include<math.h> int main(void) { char ch; int num=0; num+=ch>>0&1==1; num+=ch>>1&1==1; num+=ch>>2&1==1; num+=ch>>3&1==1; num+=ch>>4&1==1; num+=ch>>5&1==1; num+=ch>>6&1==1; num+=ch>>7&1==1; printf(“字符’%c’的二进制表示中含有%d个1n”,ch,num); system(“pause”); return 0; }

数的阶乘计算器

数的阶乘计算器

/* 功能:数的阶乘计算器 日期:2013-4-19 */ #include <stdio.h> #include <stdlib.h> #include<math.h> int main(void) { int x,i=0,t=1; printf(“请输入需要计算阶乘的数字:”); scanf(“%d”,&x); for (i=1,t=1;i<=x;i++) { if (x<0) {do { printf(“Error,请重新输入:”); scanf(“%d”,&x); }while(x>0); } else { t=t*i; } } printf(“%d的阶乘是:%dn”,x,t); system(“pause”); return 0; }

判断水仙花数

判断水仙花数

/* 功能:判断水仙花数 日期:2013-4-19 */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int n,i,j,k; printf(“水仙花数为:”); for (n=100;n<1000;n++) { i=n/100; j=(n%100)/10; k=n%10; if (i*100+j*10+k==i*i*i+k*k*k+j*j*j) { printf(“%d “,n); } } printf(“n”); system(“pause”); return 0; }

四则运算、幸福来敲门、求一次方程解ax+b=0

四则运算、幸福来敲门、求一次方程解ax+b=0

/* 功能:四则运算 日期:2013-03-16 */ #include<stdio.h> #include<stdlib.h> int main(void) { float a,b,quo,ave; int sum,dif,pro; printf(“请输入两个整数(以逗号隔开):”); scanf(“%f,%f”,&a,&b); sum=a+b; dif=a-b; pro=a*b; quo=a/b; ave=(a+b)/2; printf(“n两个数的和、差、积、商为:%d, %d, %d, %.3fnn”,sum,dif,pro,quo); printf(“n两个数的平均值为:%.1fnn”,ave); system(“pause”); return 0; } ———————————————————————————————————————————— /* 功能:求一次方程解ax+b=0 日期:2013-3-16 */ #include<stdio.h> #include<stdlib.h> int main(void) { int a,b; int x; printf(“请输入一次方程的系数a和b(以逗号隔开):”); scanf(“%d,%d”,&a,&b); x = ( -b )/a; printf(“n一次方程%dx+%d=0的根是x=%dnn”,a,b,x); system(“pause”); return 0; } /* 功能:幸福来敲门 日期 */ #include<stdio.h> #include<stdlib.h> #include<windows.h> #include<mmsystem.h> #pragma comment(lib,“WINMM.LIB”) int main(void) { printf(“请欣赏:《幸福来敲门》nn”); PlaySound(TEXT(“DOOR1.wav”),0,SND_FILENAME|SND_ASYNC); system(“pause”); return 0; } ————————————————————————————————————————————