zoukankan      html  css  js  c++  java
  • Chapter 5 :Operators,Expressions and Statements

    1. Assume all variables are of type int. Find the value of each of the following variables:

    a.  x = (2 + 3) * 6; 

    b.  x = (12 + 6)/2*3;

    c. y = x = (2 + 3)/4;

    d. y = 3 + 2*(x = 7/2);

    a. x = 30    b. x = 27    c. y = 1, x = 1    d. x = 3, y = 9


    ​​​​​​2. Assume all variables are of type int. Find the value of each of the following variables:

    a. x = (int) 3.8 + 3.3;

    b. x = (2 + 3) * 10.5;

    c.   x = 3 / 5 * 22.0;

    d.   x = 22.0 * 3 / 5;

    a. x = 6    b. x = 52    c. x = 0    d. x = 13


    3. Evaluate each of the following expressions:

    a. 30.0 / 4.0 * 5.0;

    b. 30.0 / (4.0 * 5.0);

    c.   30 / 4 * 5;

    d.   30 * 5 / 4;

    e.   30 / 4.0 * 5;

    f.   30 / 4 * 5.0;

    a. 37.5    b. 1.5    c. 35    d. 37    e. 37.5    f. 35.0


    4. What will this program print?

    #include <stdio.h>
    
    #define FORMAT "%s! C is cool
    "
    
    int main(void) {
        int num = 10;
    
        printf(FORMAT, FORMAT);
        printf("%d
    ", num);
        printf("%d
    ", ++num);
        printf("%d
    ", num++);
        printf("%d
    ", num--);
        printf("%d
    ", num);
    
        return 0;
    }
    %s! C is cool
    ! C is cool
    10
    11
    11
    12
    11
    

    5. What will this program print?

    #include <stdio.h>
    
    #define TEN 10
    
    int main(void) {
        int n = 0;
    
        while (n++ < TEN)
            printf("%5d", n);
        printf("
    ");
    
        return 0;
    }

        1    2    3    4    5    6    7    8    9   10


    6. Modify the last program so that it prints the letters a through g instead.

    #include <stdio.h>
    
    #define terminatingLetter 'g'
    
    int main(void) {
        char startingLetter = 'a';
        while (startingLetter <= terminatingLetter)
            printf("%5c", startingLetter++);
        printf("
    ");
        return 0;
    }

    7. If the following fragments were part of a complete program, what would they print?

    a. 

    int x = 0;
    
    while (++x<3)
        printf("%4d", x);

    b. 

    int x = 100;
    
    while (x++ < 103)
        printf("%4d
    ",x);
        printf("%4d
    ",x);
    

    c.

    char c = 's';
    
    while(ch<'w'){
        printf("%c", ch);
        ch++;
    }
    printf("%c
    ", ch);

    a. 

       1   2

    b. 

     101

     102

     103

     104

    c. 

    stuvw


    8. ​​​​​​​What will the following program print?

    #define MESG "COMPUTER BYTES DOG"
    
    #include <stdio.h>
    
    int main(void) {
        int n = 0;
    
        while (n < 5) 
            printf("%s
    ", MESG);
            n++;
        printf("That's all.
    ");
        
        return 0;
    }
    

    This is an ill-constructed program. Because the while statement doesn't use braces, only the printf() statement is part of the loop, so the program prints the message COMPUTER BYTES DOG indefinitely until you can kill the program.

    苟利国家生死以, 岂因祸福避趋之
  • 相关阅读:
    使用mui框架后,input标签失焦后,会滚到顶部的解决方案
    接口处理请求时间过长,前台响应“服务器超时”的解决办法
    正则匹配手机号码
    使用hexo+github免费搭建个人博客网站超详细教程
    微信小程序获取当前位置 地图定位导航-详细代码
    小程序 获取当前所在地理位置 城市 信息
    溯源:Cesium.Appearance 中的顶点着色器
    【Cesium 颜狗初步】fabric 材质定义与自定义着色器实践
    VM创建虚拟机报错
    zxing.net生成二维码的000026问题
  • 原文地址:https://www.cnblogs.com/chintsai/p/11829256.html
Copyright © 2011-2022 走看看