zoukankan      html  css  js  c++  java
  • c primer plus 5编程练习

    1、

    #include <stdio.h>
    
    #define M_PER_HOUR 60
    
    int main(void)
    {
        int min;
        
        int hour, min_left;
        
        printf("please input the minutes to convert: ");
        scanf("%d", &min);
        
        while(min > 0)
        {
            hour = min / M_PER_HOUR;
            min_left = min % M_PER_HOUR;
            
            printf("%d minutes is %d hour and %d min.
    ", min, hour, min_left);
            
            printf("please input minutes to convert again: ");
            scanf("%d", &min);
        }
        
        return 0;
    }

    2、

    #include <stdio.h>
    
    int main(void)
    {
        int num;
        int end;
    
        printf("please input an integer: ");
        scanf("%d", &num);
        end = num + 10;
        
        while(num <= end)
        {
            printf("%d	", num);
            num++;    
        }
        
        return 0;
    }

    3、……

    #include <stdio.h>
    
    #define DAYS_PER_WEEK 7
    
    int main(void)
    {
        int days;
        int week, days_left;
        
        printf("please input days: ");
        scanf("%d", &days);
        
        while(days > 0)
        {
            week = days / DAYS_PER_WEEK;
            days_left = days % DAYS_PER_WEEK;
            
            printf("%d days is %d week and %d days.
    ", days, week, days_left);
            
            printf("please input days again: ");
            scanf("%d", &days);
        }
        
        return 0;
    }

    4、

    #include <stdio.h>
    
    #define CM_PER_FEET 36.4  //???
    #define CM_PER_INCHES 15.5  // ???
    
    int main(void)
    {
        float height;
        float feet, inches;
        
        
        printf("please input height: ");
        scanf("%f", &height);
        
        while(height > 0)
        {
            feet = height / CM_PER_FEET;
            inches = height / CM_PER_INCHES;
            
            printf("height in cm: %.1f.
    ", height);
            printf("height in feet: %.1f
    ", feet);
            printf("height in inches: %.1f
    ", inches);
            
            printf("please input height again: ");
            scanf("%f", &height);
        }
        
        return 0;
    }

     

    5、

    #include <stdio.h>
    
    int main(void)
    {
        int count, sum;
        int days;
        
        count = 0;
        sum = 0;
        
        printf("please input the days: ");
        scanf("%d", &days);
        
        while(count++ < days)
            sum = sum + count;
        printf("sum = %d
    ", sum);
        
        return 0;
    }

    6、

    #include <stdio.h>
    
    int main(void)
    {
        int count, sum;
        int days;
        int tmp;
        
        count = 0;
        sum = 0;
        
        printf("please input the days: ");
        scanf("%d", &days);
        
        while(count++ < days)
        {
            tmp = count * count; 
            sum = sum + tmp;
        }
        printf("sum = %d
    ", sum);
        
        return 0;
    }

    7、

    #include <stdio.h>
    
    void cubic(double n);
    
    int main(void)
    {
        double num;
        
        printf("please input an num: ");
        scanf("%lf", &num);
        
        cubic(num);
        
        return 0; 
    }
    
    void cubic(double n)
    {
        printf("cubic of %.2f: %.2f.
    ", n,  n * n * n);
    }

    8、

    #include <stdio.h>
    
    int main(void)
    {
        int num1, num2;
        int remainder;
        
        printf("please input num1: ");
        scanf("%d", &num1);
        
        printf("please input num2: ");
        scanf("%d", &num2);
        
        while(num2 > 0)
        {
            remainder = num2 % num1;
            
            printf("%d %% %d is %d.
    ", num2, num1, remainder);
            
            printf("please input num2 again: ");
            scanf("%d", &num2);
        }
        
        return 0;
    }

    9、

    #include <stdio.h>
    
    void Temperatures(double n);
    
    int main(void)
    {
        double tempera;
        int test;
        
        printf("please input the temperature: ");
        test = scanf("%lf", &tempera);
        
        while(test == 1)
        {
            Temperatures(tempera);
            
            printf("please input the temperature again: ");
            test = scanf("%lf", &tempera); 
        }
        
        return 0;
    }
    
    void Temperatures(const double n)
    {
        double shishetem, kaishitem;
        
        shishetem = 5.0 / 9.0 * (n - 32.0);
        kaishitem = n + 273.16;
        
        printf("huashitem: %.2f.
    ", n);
        printf("shishitem: %.2f.
    ", shishetem);
        printf("kaishitem: %.2f.
    ", kaishitem);
        
    }

  • 相关阅读:
    软工实践1816-第四次作业
    软工实践1816-第三次作业
    软工实践1816-第二次作业
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    福大软工 · 第七次作业
    福大软工 · 第八次作业(课堂实战)- 项目UML设计(团队)
    福大软工1816 · 第六次作业
    福大软工1816 · 第五次作业
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15135402.html
Copyright © 2011-2022 走看看