#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"numerb of bytes in int is "<<sizeof(int)<<endl;
cout<<"numerb of bytes in long int is "<<sizeof(long)<<endl;
cout<<"numerb of bytes in shott int is "<<sizeof(short)<<endl;
cout<<"numerb of bytes in float is "<<sizeof(float)<<endl;
cout<<"numerb of bytes in double is "<<sizeof(double)<<endl;
cout<<"numerb of bytes in long double is "<<sizeof(long double)<<endl;
cout<<"numerb of bytes in char is "<<sizeof(char)<<endl;
return 0;
}
#include<iostream> //预编译处理命令
using namespace std; //标准名字空间
int main() //主函数
{
int a,b,c,d;
a=4;
b=a;
a=5;
c=d=6;
c*=a; //c=c*a
d%=a+b; //d=d%(a+b)
cout<<"a = "<<a<<endl //输出结果
<<"b = "<<b<<endl
<<"c = "<<c<<endl
<<"d = "<<d<<endl;
system("pause");
}
#include "stdafx.h"
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a,b,c,d,t;
a=4;
b=a;
a=5;
c=d=6;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
cout<<"d="<<d<<endl;
c*=a;
d%=a+b;
//等价于:
//d=d%(a+b);
t=a; //交换a b的值
a=b; //
b=t; //
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
cout<<"d="<<d<<endl;
return 0;
}
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
short a,b,c,d;
char i,j;
a=1000;
b=1000;
c=a+b;
d=a*b;
i=a;
j=125;
cout<<"c="<<c<<endl;
cout<<"d="<<d<<endl; //
cout<<"i="<<i<<endl; //
cout<<"j="<<j<<endl;
return 0;}
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
int ab,bc;
double b=3.14;
char c='A';
ab=int(b);
bc=int(c);
cout<<"b="<<b<<endl;
cout<<"ab="<<ab<<endl;
cout<<"c="<<c<<endl;
cout<<"bc="<<bc<<endl;
return 0;
}
#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double a,b,c,S,P,t;//a,b,c为三边,S为面积,P为周长
char key=1,exit,K;
while(key)
{
cout<<"请分别输入三角形的三个边:"<<endl;
cin>>a>>b>>c;
P=a+b+c;
t=P/2;
S=sqrt(t*(t-a)*(t-b)*(t-c));
cout<<"该三角形的面积为:"<<S<<endl
<<"该三角形的周长为:"<<P<<endl;
K=1;
cout<<"是否计算下一个?enter:Y or N"<<endl;
while (K)
{
cin>>exit;
if(exit=='Y'||exit=='y')
{key=1;K=0;}
else if(exit=='N'||exit=='n')
{key=0;K=0;}
else
cout<<"无效按键,按N结束,按Y计算下一个"<<endl;
}
}
return 0;
}
#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int e=1,f=4,g=2,a=7;
float m=10.5,n=4.0,k;
float x=2.5,y=4.7,z;
k=(e+f)/g+sqrt((double)n)*1.2/g+m;
//(e+f)/g=2,
//sqrt((double)n)=2.0,
//sqrt((double)n)*1.2/g=1.2;
//k=2+1.2+10.5
z=x+a%3*(int(x+y)%2)/4;
//括号优先int(x+y)=7,
//int(x+y)%2=1,
//a%3=1,
//a%3*(int(x+y)%2)=1,
//a%3*(int(x+y)%2)/4=0,
//z=x+a%3*(int(x+y)%2)/4=2.5+0=2.5
cout<<"k="<< k<<endl
<<"z="<<z<<endl;
return 0;
}
#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double a,b,c,x1,x2,t,Re,Im;
cout<<"请分别输入方程二次项、一次项、常数项系数"<<endl;
cin>>a>>b>>c;
t=b*b-4*a*c;
//可以使用幂函数pow(),
//t=pow(b,2)-4*a*c;
if(t>=0)
{
x1=(-b+sqrt(t))/(2*a);
x2=(-b-sqrt(t))/(2*a);
cout<<"x1="<<x1<<endl
<<"x2="<<x2<<endl;
}
else
{
Re=(-b)/(2*a);
Im=sqrt(-t)/(2*a);
cout<<"X1="<<Re<<"+"<<Im<<"i"<<endl;
cout<<"X2="<<Re<<"-"<<Im<<"i"<<endl;
}
return 0;
}
#include "stdafx.h"
#include<iostream>
#include<cstring>
using namespace std;
#define uchar unsigned char
void jiami(uchar s);
int _tmain(int argc, _TCHAR* argv[])
{
uchar i,k;
char xm[20];
cout<<"请输入您的英文名"<<endl;
cin.get(xm,20);
k=strlen(xm);
for(i=0;i<k;i++)
jiami(xm[i]);
cout<<endl;
return 0;
}
void jiami(uchar s)
{
uchar a,b;
a=~s;
b=a+2;
cout<<b;
}