第二章例题

// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
	cout<<"number of bytes in int is:"<<sizeof(int)<<endl;
	cout<<"number of bytes in long int is:"<<sizeof(long)<<endl;
	cout<<"number of bytes in short int is:"<<sizeof(short)<<endl;

	return 0;
}

// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
bool flag=true;
cout<<flag<<endl;
cout<<boolalpha<<flag<<endl;
cout<<flag+5<<endl;
flag=0;
cout<<"执行语句flag=0;后flag的值为:"<<boolalpha<<flag<<endl;
flag=0.0;
cout<<"执行语句flag=0.0;后flag的值为:"<<boolalpha<<flag<<endl;

return 0;
}

// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
int a,b,c,d;
a=4;
b=a;
a=5;
c=d=6;
c*=a;
d%=a+b;
cout<<"a="<<a<<endl
    <<"b="<<b<<endl
    <<"c="<<c<<endl
    <<"d="<<d<<endl;

return 0;
}

// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
short i,j,m,n;
i=1000;
j=1000;
m=i+j;
n=i*j;
cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;


return 0;
}

// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
int i=6,j,k,temp;
j=++i;
k=i++;
++i=1;
cout<<"i="<<i<<endl
    <<"j="<<j<<endl
	<<"k="<<k<<endl;


return 0;
}


// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{ 
char ch;  
   cout << "Please input a character:";  
   cin >> ch;  
    ch= ch >= 'a'&&ch<='z'?ch-'a'+'A':ch;  
   cout << "The result is :"<< ch << endl;  
   ch= ch >='A' &&ch<='Z'?ch+'a'-'A':ch;  
   cout << "The result is :"<< ch << endl;


return 0;
}

// 123.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{ 
int ab,ac;  
   double b = 3.14;  
    char c = 'A',ad;  
   ab = int(b);  
   ac = int(c);  
   ad = char(int(b));  
    cout << "b = "<<b<<endl;  
    cout << "ab = "<<ab<<endl;  
    cout << "c = "<< c << endl;  
    cout << "ac = " << ac <<endl;  
    cout << "ad = " << ad << endl;


return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值