vlambda博客
学习文章列表

C语言作业-顺序结构

1.温度转换
#include<stdio.h>
int main()
{
float f,c;
scanf("%f",&f);
c=5.0*(f-32)/9.0;
printf("f=%+.2f,c=%+.2f\n",f,c);
return 0;
}
2.银行还款
#include<stdio.h>
#include<math.h>
int main()
{
 float d=200000,p=5000,r=0.01,m;
 m=log10(p/(p-d*r))/log10(1+r);
 printf("m=%-6.1f\n",m);
 return 0;
}
3.三位数各位数字立方和
#include<stdio.h>
int main()
{
int a,Hundred,Ten,Indiv,sumcube;
scanf("%d",&a);
Hundred=a/100;
Ten=(int)(a-Hundred*100)/10;
    Indiv=(int)(a-Hundred*100-Ten*10);
    sumcube=Hundred*Hundred*Hundred+Ten*Ten*Ten+Indiv*Indiv*Indiv;
printf("sumcube=%d\n",sumcube);
return 0;
}
4.时间转分钟
#include<stdio.h>
int main()
{
int h,m,minu;
scanf("%d:%d",&h,&m);
minu=h*60+m;
printf("minu=%d\n",minu);
return 0;
}
5.求和运算
#include<stdio.h>
int main()
{
float a,b,sum;
scanf("%f %f",&a,&b);
sum=a+b;
printf("%8.6f,%8.6f,%8.6f\n",a,b,sum);
return 0;
}