第三章 最简单的C程序设计---顺序程序设计(1)

最简单的C程序设计---顺序程序设计(1)


3.1 顺序程序设计举例
例3.1 有人用温度计测量出用华氏法表示的温度(如64°F),今要求把它转换成以摄氏法表示的温度(如17.8°C)。

#include<stdio.h>
int main()
{
 float f,c;
 f=64.0;
 c=(5.0/9)*(f-32);
 printf("f=%f\nc=%f\n",f,c);
 return 0;
}

运行结果如下:在这里插入图片描述
例3.2 计算存款利息。有1000元,想存一年。有三种方法可选:(1)活期,年利率为r1;(2)一年期定期,年利率为r2;(3)存两次半年定期,年利率为r3。请分别计算出一年后按3种方法所得到的本息和。

#include<stdio.h>
int main()
{
 float p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;
 p1=p0*(1+r1);
 p2=p0*(1+r2);
 p3=p0*(1+r3/2)*(1+r3/2);
 printf("p1=%f\np2=%f\np3=%f\n",p1,p2,p3);
    return 0;
}

运行结果如下:在这里插入图片描述
例3.3 给定一个大写字母,要求用小写字母输出。

#include <stdio.h>
int main ( )
{
   char c1,c2;
   c1='A'; 
   c2=c1+32;                       
   printf("%c\n",c2);            
   printf("%d\n",c2); 
   return 0;
}

运行结果如下:在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44571614/article/details/86770914
今日推荐