• C++入门2.0基本类型


    #include<limits.h>
    #inclede<iostream>
    #define ZERO 0 //
    
    int main()
    {
    	using namespace std;
    	//----------------------1.0 测试整形基本数据类型的长度,还有最大值--------------
    
    	////赋予最大值
    	//int limit_int=INT_MAX;
    	//short limit_short=SHRT_MAX;
    	//long limit_long=LONG_MAX;
    	//long long limit_llong=LLONG_MAX;
     //   
    	////输出所占字节
    	//cout<<"int is : "<<sizeof(int)<<" bytes"<<endl;
    	//cout<<"short is : "<<sizeof(short)<<" bytes"<<endl;
    	//cout<<"long is : "<<sizeof(long)<<" bytes"<<endl;
    	//cout<<"long long is : "<<sizeof(long long)<<" bytes"<<endl;
     //   
    	////打印出最大值
    	//cout<<"Maximum values:"<<endl;
    	//cout<<"int : "<<limit_int<<endl;
    	//cout<<"short : "<<limit_short<<endl;
    	//cout<<"long : "<<limit_long<<endl;
    	//cout<<"long long is : "<<limit_llong<<endl;
    
    	//----------------------2.0 无符号类型 +1 -1时候的现象 --------------
    
    	//最大值 +1
    	//short sam=SHRT_MAX;
    	//unsigned short sue=sam;
    
    	//cout<<"sam has "<<sam<<"RMB"<<endl;
    	//cout<<"sue has "<<sue<<"RMB"<<endl;
    	//cout<<"add 1yuan to each account"<<endl;
    
    	//sam++;
    	//sue++;
    
    	//cout<<"sam has "<<sam<<"RMB"<<endl;
    	//cout<<"sue has "<<sue<<"RMB"<<endl;
    
    	////最小值 -1 
    	//sam=ZERO;
    	//sue=ZERO;
    	//cout<<"sam has "<<sam<<"RMB"<<endl;
    	//cout<<"sue has "<<sue<<"RMB"<<endl;
    
    	//cout<<"take 1yuan form each account"<<endl;
    	//sam--;
    	//sue--;
    	//
    	//cout<<"sam has "<<sam<<"RMB"<<endl;
    	//cout<<"sue has "<<sue<<"RMB"<<endl;
    
    
    	//----------------------3.0 使用 8进制,10进制,16进制赋值--------------------
    
    	//int decimal=199;//十进制
    	//int octal=077;//八进制
    	//int hexadecimal=0x6F;//十六进制
    
    	//cout<<"decimal : "<<decimal<<endl;
    	//cout<<"octal : "<<octal<<endl;
    	//cout<<"hexadecimal : "<<hexadecimal<<endl;
    
    	//----------------------4.0 十进制输入,8进制,16进制输出 --------------------
    
    	//int chest=45;
    	//int waist=45;
    	//int inseam=45;
    
    	//cout<<"decimal "<<chest<<endl;
    	//
    	//cout<<oct;//转换为8进制显示
    	//cout<<"octal "<<waist<<endl;
    
    	//cout<<hex;//转换为16进制显示
    	//cout<<"the hexadecimal "<<inseam<<endl;
    
    	//cout<<dec;//转换为默认十进制输出
    	//cout<<"decimal "<<chest<<endl;
    
    	//----------------------5.0 字符转换数字并输出,用cout.put()函数  --------------------
    
    	//char keychar='y';
    	//int keyint=keychar;//将y对应的 ASCII码存储在int变量中
    	//cout<<"Keychar : "<<keychar<<endl;
    	//cout<<"The ASCII code for Keychar is : "<<keyint<<endl;
    
    	//
    	//keychar++;//字符+1 效果显示下一个字幕
    	//keyint=keychar;
    	//cout<<"Keychar : "<<keychar<<endl;
    	//cout<<"The ASCII code for Keychar is : "<<keyint<<endl;
    
    	//cout<<"Displaying char keychar using cout.put()"<<endl;
    	//cout.put(keychar);//直接输出char变量
    	//cout.put('!');
    	//cout<<endl;
    
    	//----------------------6.0 转义字符的  --------------------
    	//
    	//cout<<"\a"<<endl;//发出振铃
    	//cout<<"i say \"happy\",and what you think?"<<endl;//输出双引号
    	//cout<<"Enter you agent code:______";
    	//cout<<"\b\b\b\b\b\b";//退格键
    	//int number;
    	//cin>>number;
    	//cout<<"You Entered "<<number<<endl;
    
    
    	//----------------------7.0 浮点数的精度 --------------------
    
    	//float a=2.34E+22;
    	//float b=a+1.0f;
    	//cout<<"b= "<<b<<endl;
    	//cout<<"a = "<<a<<endl;//float 只能表示数字中的前六位,所以第二十三位忽略不计
    	//cout<<"b-a = "<<b-a<<endl;
    
    	//----------------------8.0 算数运算符 --------------------
    	
    	cout.setf(ios_base::fixed,ios_base::floatfield);//按浮点打印输出
    	float hats,heads;
    
    	cout<<"Enter a number : ____\b\b\b\b";
    	cin>>hats;
    	cout<<"Enter another  number____\b\b\b\b ";
    	cin>>heads;
    
    	cout<<"hats = "<<hats<<"; heads = "<<heads<<endl;
    	cout<<"hats + heads = "<<hats+heads<<endl;
    	cout<<"hats - heads = "<<hats-heads<<endl;
    	cout<<"hats * heads = "<<hats*heads<<endl;
    	cout<<"hats /heads = "<<hats/heads<<endl;
    	//cout<<"hats%heads = "<<hats%heads<<endl;//不能求模,求模要求都是整形数字。
    
    
    
    	
    
    
    	cin.get();
    	return 0;
    
    } 
    

  • 相关阅读:
    乘积最大(动规)
    电话圈(floyd)
    孪生蜘蛛
    解题报告
    最大上升子序列和
    怪盗基德的滑翔翼(还是最长x序列)
    最长公共子序列
    合唱队形(动规,最长不下降子序列)
    课堂笔记 4.6
    2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I Lottery
  • 原文地址:https://www.cnblogs.com/incyanggan/p/3176944.html
Copyright © 2020-2023  润新知