初学C++

来源:互联网 发布:搜索一下淘宝网 编辑:程序博客网 时间:2024/05/29 16:18

最近在系统的初步学习c++,下面是写的小程序以供参考:

//符号==和&&和z/2.的用法
/*
#include<iostream>
using namespace std;
int main()
{
 int x, y, z;
 for(x=0;x<=9;x++)
  for(y=0;y<=12;y++)
   for(z=0;z<=36;z++)
    if((4*x+3*y+z/2.==36)&&(x+y+z==36))//此句写错;必须满足条件的才输出,要用if语句
 cout<<"x="<<x<<" y= "<<y<<" z="<<z<<'\n';
 system ("pause");
 return 0;
}
*/

 


//结果是 10      12      19      41
/*
#include <iostream>
using namespace std;
int main()
{
 int i,j,m,n;
 i=8;
 j=10;
 m=++i+j++;//m里i=9;j=10;m=19;执行完此句j=11
 n=(++i)+(++j)+m;//n里i=10;j=12;m=19;n=41
 cout<<i<<'\t'<<j<<'\t'<<m<<'\t'<<n<<'\t'<<'\n';
 system ("pause");
 return 0;
}
*/

 

//\"输出字符的意思;  \t\t跳过12个字符 
//结果是:I say:"C++"        He says:"C++ is very interesting"
/*
#include <iostream>
using namespace std;

int main()
{
 char c1='C', c2='+', c3='+';
 cout<<"I say:\""<<c1<<c2<<c3<<'\"';
 cout<<"\t\t"<<"He says: \"C++ is very interesting\""<<'\n';
 system("pause");
}
*/

 

//"\t"跳过6个字符位置;"\n"换行;"\101"=A; "\116"=N;
/*
#include <iostream>
using namespace std;

int main()
{
 char c1, c2, c3, c4, c5;
 c1='a';
 c2='b';
 c3='c';
 c4='\101';
 c5='\116';
 cout<<c1<<c2<<c3<<'\n';
 cout<<"\t\d"<<c4<<"\t"<<c5<<'\n';
 system ("pause");
 return 0;
}
*/

 

 

//符号定义const用法
/*
#include<iostream>
using namespace std;

int main()
{
 int num, total;
 const int PRICE=30;
 num=10;
 total=num*PRICE;
 cout<<"total="<<total<<endl;
 system ("pause");
 return 0;
}
*/

 


//符号定义#define用法
/*
#include<iostream>
using namespace std;
#define PRICE 30
int main()
{
 int num, total;
 num=10;
 total=num*PRICE;
 cout<<"total="<<total<<endl;
 system ("pause");
 return 0;
}
*/

 

 

//字符常量练习
/*
#include <iostream>
using namespace std;

int main ()
{
 int c1,c2;
 c1='a';
 c2='b';
 c1=c1-32;
 c2=c2-32;
 cout<<c1<< ' '<<c2<<"\n";
 system("pause");
 return 0;
}
*/

 

 


//从小到大排序
/*
#include <iostream>
using namespace std;


void sort(int x, int y, int z)
{
 int temp;
 if(x>y) {temp=x; x=y; y=temp;}
 if(z<x) cout<<z<<","<<x<<","<<y<<endl;
 else if(z<y) cout<<x<<","<<z<<","<<y<<endl;
 else cout<<x<<","<<y<<","<<z<<endl;
}

int main()
{
 int a ,b,c;
 void sort(int x, int y, int z);
 cin>>a>>b>>c;
 sort(a,b,c);
 system ("pause");
 return 0;
}
*/

 

原创粉丝点击