#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 "); for(fahr=lower;fahr<=upper;fahr++){ celsius=(5.0/9.0)*(fahr-32); printf("%d%6.1f ",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 ",sum); return 0; }
/* 计算二分段函数 */ #include<stdio.h> int main(void) { double x,y; printf("Enter x(x>=0): "); scanf_s("%lf",&x); if(x<=15){ y=4*x/3; } else{ y=2.5*x-10.5; } printf("y=f(%f)=%.2f ",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 ",fahr,celsius); return 0; }
/* 显示 “Hello World!” */ # include<stdio.h> int main(void) { printf("Hello World! "); return 0; }