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.

    苟利国家生死以, 岂因祸福避趋之
  • 相关阅读:
    pageControl点击白点时会变
    valueForKeyPath获取对象数组的属性
    探讨:通过循环数组或者集合,插入数据库中没有的数据
    Mybatis 中 Oracle 的拼接模糊查询
    Spring boot 中 Mybatis Plus 在 Oracle 新增数据时,主键自增问题
    在IntelliJ IDEA中,SpringBoot项目通过devtools实现热部署
    在 Mybatis 中遇到的那些坑
    华硕飞行堡垒耳机插进去之后再拔出来,电脑就没有声音了
    nyoj 776 删除元素
    nyoj 14 会场安排问题(贪心专题)java
  • 原文地址:https://www.cnblogs.com/chintsai/p/11829256.html
Copyright © 2011-2022 走看看