zoukankan      html  css  js  c++  java
  • 【C Primer Plus】编程练习第四章

    1、

    #include <stdio.h>
    
    int main()
    {
        char a[10] = { 0 };
        char b[10] = { 0 };
        printf("请输入您的姓名:");
        scanf("%s,%s", a, b);
        getchar();
        printf("欢迎您%s,%s",a, b);
        getchar();
        return 0;
    }

    2、

    #include <stdio.h>
    #include <string>
    int main()
    {
        char a[100] = { 0 };
        printf("请输入您的姓名:");
        scanf("%s",a);
        getchar();
        int len = strlen(a);
        printf("%d
    ", len);
        printf(""%s"
    ",a);
        printf(""%20s"
    ", a);
        printf(""%-20s"
    ", a);
        printf(""%*s"",len+3, a); //如果后面只有一个参数,*没有意义,如果有两个参数,*代表打印数据长度,本句相当于 printf(""%10s"",a)
        getchar();
        return 0;
    }

     3、

    #include <stdio.h>
    #include <string>
    int main()
    {
        float f=0;
        printf("请输入一个浮点数:");
        scanf("%f",&f);
        getchar();
        printf("The input is %0.1f or %0.1e", f, f);
        
        getchar();
        return 0;
    }

     4、

    #include <stdio.h>
    #include <string>
    int main()
    {
        char name[20] = { 0 };
        float f=0;
        printf("请输入你的姓名和身高:");
        scanf("%s %f", name,&f); //这里要注意如果采用逗号来分隔的话,会导致&f并不会接收到数据,只有空格才能表示字符串输入结束
        getchar();
        printf("%s,you are %f feet tall", name,f);
        getchar();
        return 0;
    }

     5、

    #include <stdio.h>
    #include <string>
    int main()
    {
        float speed, file,time,speeds;
        printf("请输入下载速度和文件大小:");
        scanf("%f,%f", &speed, &file);
        getchar();
        speeds = speed / 8;  //题中给出的为bit,要化为byte
        time = file / speeds;
        printf("At %0.2f megabits per second,a file of %0.2f megabytes
    ",speed,file);
        printf("downloads in %0.2f seconds", time);
        getchar();
        return 0;
    }

     

     6、

    #include <stdio.h>
    #include <string>
    int main()
    {
        char xin[10] = { 0 };
        char min[10] = { 0 };
        printf("请输入您的名:");
        scanf("%s", min);
        getchar();
        printf("请输入您的姓:");
        scanf("%s", xin);
        getchar();
        int len_x, len_m;
        len_x = strlen(xin);
        len_m = strlen(min);
        printf("%s,%s
    ", min, xin);
        printf("%*d,%*d
    ", len_m, len_m, len_x, len_x);
        printf("%s,%s
    ", min, xin);
        printf("%-*d,%-*d", len_m, len_m, len_x, len_x);
        getchar();
        return 0;
    }

     7、

    #include <stdio.h>
    #include <string>
    int main()
    {
        double a = 1.0 / 3.0;
        float b = 1.0 / 3.0;
        printf("%0.6lf,%0.6lf
    ", a, b);
        printf("%0.12lf,%0.12lf
    ", a, b);
        printf("%0.18lf,%0.18lf
    ", a, b);
        printf("%d,%d
    ", FLT_DIG, DBL_DIG);  //这两个宏在float.h头文件下面,用来说明double、float两种数据类型有效数字的位数,注意不是小数点后面的有效位数,而是所有位数。
        getchar();
        return 0;
    }

     8、

    #include <stdio.h>
    #include <string>
    #define GALLON 3.785
    #define MILE 1.609*100
    int main()
    {
        float gallon = 0;
        float mile = 0;
        double gal_mil = 0;
        double l_m=0;
        printf("请输入里程和耗油量:");
        scanf("%f,%f", &mile, &gallon);
        getchar();
        gal_mil = mile / gallon;
        printf("消耗每加仑行驶英里数为:%0.1lf
    ", gal_mil);
        l_m = (gallon*GALLON) / (MILE*mile);
        printf("把它化为升每一百公里:%0.1lf", l_m);
        getchar();
        return 0;
    }

     

  • 相关阅读:
    爬虫(4)_代码分析
    python(32)——【shelve模块】【xml模块】
    python(31)——【sys模块】【json模块 & pickle模块】
    python(30)——【random模块】【if __name__ =='__main__'】【os模块】
    机器学习与Tensorflow(7)——tf.train.Saver()、inception-v3的应用
    机器学习与Tensorflow(6)——LSTM的Tensorflow实现、Tensorboard简单实现、CNN应用
    机器学习与Tensorflow(5)——循环神经网络、长短时记忆网络
    机器学习与Tensorflow(4)——卷积神经网络与tensorflow实现
    机器学习与Tensorflow(3)—— 机器学习及MNIST数据集分类优化
    机器学习与Tensorflow(2)——神经网络及Tensorflow实现
  • 原文地址:https://www.cnblogs.com/roscangjie/p/11792167.html
Copyright © 2011-2022 走看看