练习

时差计数器

#include <stdio.h>

int main(){

// 计算时差
int hourse1,minute1;
int hourse2,minute2;

scanf("%d %d %d %d",&hourse1,&minute1,&hourse2,&minute2);

int value = (minute2+hourse2*60)-(minute1+hourse1*60);

printf("时间差是: %d时,%d分\n",value/60,value%60);
return 0;
}

身高换算器

#include <stdio.h>
int main(){
printf("请分别输入身高的英尺和英寸:\n(如: '5 7' 等价于 5英尺7英寸)");
double foot;
double inch;

scanf("%lf %lf",&foot,&inch);
printf("身高是%f米。\n=>",((foot+inch/12)*0.3048));
return 0;
}

计算复利

#include "stdio.h"

int main(){
int xf;
// 常量1
const double Val = 1.0;
// 利率3.3%
const double L = 0.003;
printf("请输入本金:");
scanf("%d", &xf);
// 转存3年的量
double amount = xf*(Val+L)*(Val+L)*(Val+L);
printf("value: %f\n",amount);

return 0;
}