小宝的第二章
#include<stdio.h> int main(void) { int fahr,lower,upper; double celsius; printf("Enter lower:"); scanf_s("%d",&lower); printf("Enter upper:"); scanf_s("%d",&upper); printf("fahr celsius\n"); for(fahr=lower;fahr<=upper;fahr++){ celsius=(5.0/9.0)*(fahr-32); printf("%d%6.1f\n",fahr,celsius); } return 0; }
/* 计算存款的本息 */ #include<stdio.h> #include<math.h> int main(void) { int money,year; double rate,sum; printf("Enter money:"); scanf_s("%d",&money); printf("Enter year:"); scanf_s("%d",&year); printf("Enter rate:"); scanf_s("%lf",&rate); sum=money*pow(1+rate,year); printf("sum=%.2f\n",sum); return 0; }
/* 计算二分段函数 */ #include<stdio.h> int main(void) { double x,y; printf("Enter x(x>=0):\n"); scanf_s("%lf",&x); if(x<=15){ y=4*x/3; } else{ y=2.5*x-10.5; } printf("y=f(%f)=%.2f\n",x,y); return 0; }
/* 将华氏温度转换为摄氏温度 */ #include<stdio.h> int main(void) { int celsius,fahr; fahr=100; celsius=5*(fahr-32)/9; printf("fahr=%d,celsius=%d\n",fahr,celsius); return 0; }
/* 显示 “Hello World!” */ # include<stdio.h> int main(void) { printf("Hello World!\n"); return 0; }