11.25(下午

C Prime Plus 1-4章的浏览......

哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈,C Prine Plus 这本数细节内容真是够多的,看着真是感觉自己打开了新世界,每一处都是精华,可惜太多了QAQ,有些读过就忘记啦,好多头文件用法呀,哈哈哈哈。

<( ̄︶ ̄)↗[GO!] ,每天坚持一点点,迟早会有收获的

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<float.h>

#define PI 3.141159
#define PRAISE "You are an extraordinary being."
#define PAGES 959
#define BLURB "Authentic"
#define PAGE  336
#define WORDS 65618

int main()
{
    /* showf_pt.c--以俩种方式显示float类型的值*/
    float aboat =3200.0;
    double abet =2.14e9;
    long double dip =5.32e-5;
    printf("%f can be written %e\n",aboat,aboat);
    //C99独有
    printf("And it's %a in hexadecimal,powers of 2 notation\n",aboat);
    printf("%f can be written %e\n",abet,abet);
    printf("%Lf can be written %Lf\n\n",dip,dip); 
    
    
    
        /*toobig.c--超出系统允许的最大int类型*/
    int i=2147483647;
    unsigned int j=4294967295;
    printf("%d %d %d\n",i,i+1,i+2);
    printf("%u,%u,%u\n\n",j,j+1,j+2); 
    
    
    
    float a,b;
    b=2.0e20+1.0;
    a=b-2.0e20;
    printf("%f \n\n",a);//【这是由于我们的float只能保存6位数据】 
    
    
    
    printf("%d\n",sizeof(char));
    printf("%d\n\n",sizeof(long long)); 
    
    
    
    float salary;
    printf("\aEnter your desired monthly salary:");
    printf("$_______\b\b\b\b\b\b\b");//【把光标左移 】 
    scanf("%f",&salary);
    printf("\n\t$%.2f a month is $%.2f a year.",salary,salary*12.0);
    printf("\rGee!");//【换页---就是把同行的输出顺序换一下】 
    printf("\n");
    
    
    
    char name[40];
    printf("What's your name?");
    scanf("%s",name);
    printf("Hello,%s. %s\n",name,PRAISE);
    printf("Your name of %zd letter occuoies %zd memory cells.\n",strlen(name),sizeof name);
    printf("The phrase of praise has %zd letters",strlen(PRAISE));
    printf("and occupies %zd memony cells.\n",sizeof PRAISE);
    
    
    
     float area ,circum,radius;
     printf("What is the radius of your pizza?");
     scanf("%f",&radius);
     area=PI*radius*radius;
     circum=2.0*PI*radius;
     printf("You basic pizza parameters are as follows:\n");
     printf("circumference=%1.2f,area=%1.2f\n",circum,area);
     
     
     
     printf("Some number limits for this system:\n");
     printf("Bigges int : %d\n",INT_MAX);
     printf("Smallest long long :%lld",LLONG_MIN);
     printf("One byte = %d bits on this system.\n",CHAR_MIN);
     printf("Largest double : %e\n",DBL_MAX);
     printf("Smallest normal float:%e\n",FLT_MIN);
     printf("float precision =%d digits\n",FLT_DIG);
     printf("float epsill =%e\n",FLT_EPSILON);
     
     
     /*width.c---字符宽度*/ 
     printf("*%d*\n",PAGES);
     printf("*%2d*\n",PAGES);
     printf("*%10d*\n",PAGES);
     printf("*%-10d*\n",PAGES);
     
     /*float.c---一些浮点型修饰符的组合*/
     const double RENT =3852.99;
      printf("*%f*\n",RENT);
      printf("*%e*\n",RENT);
      printf("*%4.2f*\n",RENT);
      printf("*%3.1f*\n",RENT);//【浮点型会自动的进行四舍五入的运算!】 
      printf("*%10.3f*\n",RENT);
      printf("*%10.3E*\n",RENT);
      printf("*%+4.2f*\n",RENT);
      printf("*%010.2f*\n",RENT);
      
      /*flags.c---演示一些格式标记*/
      printf("%x %X %#x\n",31,31,31);
      printf("**%d**% d**% d**\n",42,42,-42);
      printf("**%5d**%5.3d**%05d**%05.3d**\n",6,6,6,6);
      
      /*stringf.c---字符串格式*/
      printf("[%2s]\n",BLURB);
      printf("[%24s]\n",BLURB);
      printf("[%24.5s]\n",BLURB);//【.5表示只打印5个字符,前面24表示宽度 】 
      printf("[%-24.5s]\n",BLURB);
      
      /*intconv.c---一些不匹配的整型转换*/
       short num=PAGE;
       short mnum=PAGE;
       printf("num as short and unsigned short:%hd %hu\n",num,mnum); //【short int最大表示65536,其中32768开始表达负数】 
       printf("-num as short and unsigned short:%hd %hu\n",num,mnum);
       printf("num as int and char : %d %c\n",num,mnum);//【以“256为模”取余得到80,ASCII码80是P】 
       printf("WORDS as int,short,and char : %d %hd %c\n",WORDS,WORDS,WORDS);//【WORDS与short int最大数取余的ASCII码结果】 
       
       /*floatcnv.c---不匹配的浮点型转换*/
       float n1=3.0;
       double n2=3.0;
       long n3=2000000000;
       long n4=1234567890 ;
       printf("%1.e %.1e %.1e %.1e\n",n1,n2,n3,n4);//【float会自动转化为8字节,但long就是4字节,浮点型以8字节输出,所以n3,n4 
       printf("%ld %ld\n",n3,n4);                   // 【会补填相邻4字节的数一起输出】 
       printf("%ld%ld%ld%ld",n1,n2,n3,n4);//【我的编译器没有错,但是如果出错就是%ld只能输出4个字节,其实只能输出到double结束】
        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值