1
#include <iostream>
#include <iomanip>
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;
}
(2)
#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;
}
(3)
- #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;
- }
2
/**********************************************
** 功能:计算三角形面积和周长 *****
**********************************************/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a , b, c,d,e,S,Z;
cout <<"请输入三角形的三条边长:";
cin>>a>>b>>c;
d=1.0/2.0*(a+b+c);
e=d*(d-a)*(d-b)*(d-c);
Z=a+b+c;
S=sqrt(e);
cout <<"三角形周长为:"<<Z<<endl
<<"三角形面积为:"<<S<<endl;
return 0;
}
3(1)
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int e , f , g ;
e = 1;
f = 4;
g = 2;
float m , n , k;
m = 10.5 ;
n = 4.0;
k = (e+f)/g+sqrt((double)n)*1.2/g+m;
cout<<k<<endl;
return 0;
}
(2)
#include <iostream>
using namespace std;
int main()
{
float x , y, z;
x=2.5;
y=4.7;
int a ;
a = 7;
z=x+a%3*(int(x+y)%2)/4;
cout<<z<<endl;
return 0;
}
4, 求一元二次方程解
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
float a ,b ,c;
double delta ;
cout << "Please enter a :";
cin >> a ;
cout << endl;
cout << "Please enter b :";
cin >> b ;
cout << endl;
cout << "Please enter c :";
cin >> c ;
cout << endl;
if(a==0&&b==0)
{
cout << "该方程无解。"<< endl;
exit(0);
}
delta = (b*b)-(4*a*c) ; //求delta
if (delta >= 0){
if (delta > 0){
cout << "方程的实数根 X1= " << (-b+sqrt(delta))/(2*a) << endl;
cout << " 方程的实数根X2= " << (-b-sqrt(delta))/(2*a) << endl;
}
else cout << "方程的实数根 X1 = X2 = " << (-b)/(2*a) << endl;
}
else {
delta=abs(delta);
cout << "方程的虚根X1=" << -b/(2*a) <<"+"<<sqrt(delta)/(2*a) <<"j"<< endl;
cout << "方程的虚根X2=" << -b/(2*a) <<"-"<<sqrt(delta)/(2*a) <<"j"<< endl;
}
return 0;
}
5 加密算法
待定
6
待定