C++ Exercises(四)

1,cout<<boolalpha<<(2>3)<<endl;输出什么?

Dev c++上输出false,VC++输出0,why?

 2, 我机子上的VC6.0上编译通不过,可Dev C++可以运行,why?

#include < fstream >
using   namespace  std;

int  main()
{
    ifstream 
in ( " F://data.txt " );
    ofstream 
out ( " F://a.txt " );
    
for ( string  str; getline( in , str); )
    
out << str << endl;
    
return   0 ;
}

3
#include  < iostream >
using   namespace  std;

void  OutPutLine( int  row)
{
    
int  i;
    
for (i = 4 - row;i > 0 ;i -- )
        cout
<< "   " ;
    
for (i = 2 * row - 1 ;i > 0 ;i -- )
        cout
<< " * " ;
    cout
<< endl;
}
int  main()
{
    
int  i;
    
for (i = 1 ;i <= 4 ;i ++ )
        OutPutLine(i);
    
for (i = 3 ;i >= 1 ;i -- )
        OutPutLine(i);
    
return   0 ;
}

4
#include  < iostream >
using   namespace  std;

void  OutPutLine( int  row)
{
    
int  i;
    
for (i = 1 ;i <= row - 1 ;i ++ )
    {
        cout
<< "   " ;
    }
    
for (i = 1 ;i <= 21 - 2 * row;i ++ )
    {
        cout
<< " M " ;
    }
    cout
<< endl;
}

int  main()
{
    
for ( int  i = 1 ;i <= 10 ;i ++ )
    {
        OutPutLine(i);
    }
    
return   0 ;

}
5
#include  < iostream >
using   namespace  std;

void  OutPutLine( int  row)
{
    
int  i;
    
char  ch  =   ' A ' ;
    
for (i = 1 ;i <= 10 - row;i ++ )
    {
        cout
<< "   " ;
    }
    
for (i = 1 ;i <= 2 * row - 1 ;i ++ )
    {
        cout
<< ch;
        ch
++ ;
    }
    cout
<< endl;
}

int  main()
{
    
for ( int  i = 1 ;i <= 10 ;i ++ )
    {
        OutPutLine(i);
    }
    
return   0 ;

}
6
/* 筛法求素数 */

#include 
< iostream >
#include 
< vector >
using   namespace  std;

const   int  LEN  =   101 ;
vector
< int >  b(LEN, 1 );

void  ShaiSu()
{
    
int  i,j;

    
for (i = 2 ;i < LEN;i ++ )
    {
        
if (b[i] == 1 )
        {
            
for (j = 2 ;i * j < LEN;j ++ )
            {
                b[i
* j]  =   0 ;
            }
        }
    }
}

void  OutPut()
{
    
int  i;
    
for (i = 2 ;i < len;i ++ )
    {
        
if (b[i] == 1 )
        {
            cout
<< i << " 是素数 " << endl;
        }
    }
}
int  main()
{
    ShaiSu();
    OutPut();
    
return   0 ;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值