zoukankan      html  css  js  c++  java
  • C连载27-练习计算和数据类型

    一、练习计算和数据类型

    #include<stdio.h>
    #pragma warning(disable:4996)
    const int S_PER_M = 60;    //1分钟的秒数
    const int S_PER_H = 3600;  //1小时的秒数
    const double M_PER_K = 0.62137;  //1公里的英里数
    int D27_1_running(void) {
    	double distk, distm;     //跑过的距离(分别用以公里和英里为单位)
    	double rate;            //平均速度(以英里/小时为单位)
    	int min, sec;           //跑步用时(以分钟和秒为单位)
    	int time;               //跑步用时(以秒为单位)
    
    	double mtime;           //跑1英里需要的时间,以秒为单位
    	int mmin, msec;         //跑1英里需要的时间,以分钟和秒为单位
    
    	printf("This program converts your time for a metric race
    ");
    	printf("to a time for running a mile and to your average
    ");
    
    	printf("speed in miles per hour.
    ");
    	printf("Please enter, in kilometers,the distance run.
    ");
    	scanf("%lf", &distk);     //%lf表示读取double类型的值
    	printf("Next enter the time in minute and seconds.
    ");
    	printf("Begin by entering the minutes.
    ");
    	scanf("%d", &min);
    	printf("Now enter the seconds.
    ");
    	scanf("%d", &sec);
    	
    	time = S_PER_M * min + sec;    //把时间转换成秒
    	distm = M_PER_K * distk;       //公里换成英里
    	rate = distm / time *  S_PER_H;  //英里/秒 * 秒/小时  = 英里/小时
    	mtime = (double)time / distm;   //时间/距离 = 跑1英里的所用的时间
    	mmin = (int)mtime / S_PER_M;   //求出分钟数
    	msec = (int)mtime % S_PER_M;    //求出剩余的秒数
    
    	printf("You ran %1.2f km (%1.2f miles) in %d min,%d sec.
    ", distk, distm, min, sec);
    	printf("That pace corresponds to running a mile in %d min, ", mmin);
    	printf("%d sec.
    Your average speed was %1.2f mph.
    ", msec, rate);
    
    	return 0;
    }
    

    27.1

    二、源码:

  • 相关阅读:
    Leo程序员羊皮卷文摘(更新ing)
    ubuntu下的yuv播放器
    浏览器之一
    海量数据处理常用思路和方法(zh)
    我本将心向明月,奈何明月照沟渠
    转载光纤通信之父
    重装系统或是更换电脑之后,Foxmail的恢复
    关于录制Linux视频
    Linux之路(原发表于07年,现在搬到博客)
    Gentoo安装 miniCD+stage3
  • 原文地址:https://www.cnblogs.com/ruigege0000/p/13789709.html
Copyright © 2011-2022 走看看