20200205

今天中央发布五号方案,中国加油~

学习内容C primer plus 第三章

计算机的字长越大转移数据越快,直到目前的64位;位(bit) 字节(byte):既然1位可以表示0或1,那么8位字节就有256(2的8次方)种可能的0、1的组合。

3.16E7(3.16乘以10的7次方)    浮点数分成小数部分和指数部分来表示,而且分开存储这两部分,在十进制下,可以把7.0写成0.7E1,这里0.7是小数部分,1是指数部分。

 

#include
int main(void)
{
    float weight;
    float value;
    printf("Are you worth your weight in platinum?\n");
    printf("Let's check it out.\n");
    printf("Please enter your weight in pounds:");
    getchar();
    scanf("%f",&weight);
    value=1700.0*weight*14.5833;    
    printf("Your weight in platinum is worth $%.2f.\n",value);
    /*%f 处理浮点值 %.2中.2 表示只显示小数点后面两位。*/
    printf("You are easily worth that!if platinum prices drop.\n ");
    printf("eat more to maintain your value.\n"); 
    return 0;

    
    
 } 

大部分函数都需要指定数目的参数,编译器会检查参数的数目是否正确,但是,printf()函数的参数数目不定,可以与1个,2个,3个或更多,,编译器也不能检测

#include 
int main (void){
    int ten=10;
    int two=2;
    printf("Doing it right:");
    printf("%d minus %d is %d\n",ten ,2,ten-two);
    printf("Doing it wrong:");
    printf("%d minus %d is %d\n",ten);//遗漏两个参数 
    return 0; 
} 

#include
int main(void){
    int x = 100;
    printf("dec=%d;octal=%o;hex=%x\n",x,x,x);//%o 以八进制 显示;%x 以十六进制显示数字 
    printf("dec=%d;octal=%#o;hex=%#x\n",x,x,x);//要显示各进制数的前缀,加上# 
    return 0; 
}

 

 

 

#include
int main(void){
    char ch;
    printf("Please enter character \n");
    scanf("%c",&ch);
    printf("The codw for %c is %d.\n",ch,ch);
    return 0;
}

 

 基本上看完了第三章,其中后续部分暂时浏览,不做深究。

3.10复习题

  Q2什么情况下要使用long类型代替int类型的变量?

原因之一:在系统中要表示的数超过了int可表示的范围,这时要使用 long类型。原因之二:如果要处理更大的值,那么使用一种在所有系统上都 保证至少是 32 位的类型,可提高程序的可移植性。

 

                                              

 

你可能感兴趣的:(20200205)