1。//1。一元二次方程求解
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a,b,c;
double x1,x2;
cout<<"please input the a,b,c:"<<endl;
cin>>a>>b>>c;
if(a==0&&b==0)
cout<<"该方程没有解!"<<endl;
else if(a==0&&b!=0)
{
cout<<"x="<<-c/b<<endl;
}
else
{
long double delta=b*b-4.0*a*c;
if(delta>0)
{
cout<<"该方程有两个实数根:"<<endl;
x1=(-b)/(2.0*a)+sqrt(delta)/(2.0*a);
x2=(-b)/(2.0*a)-sqrt(delta)/(2.0*a);
cout<<"x1= "<<x1<<endl;
cout<<"x2= "<<x2<<endl;
}
else if(delta==0)
{
cout<<"该方程有两个相等的根:"<<endl;
x1=x2=-(2.0*a/b);
cout<<"x1=x2="<<x1<<endl;
}
else
{
cout<<"该方程有两个虚根:"<<endl;
cout<<"x1="<<(-b)/(2*a)<<+sqrt(delta)/(2*a)<<"i"<<endl;//
这里有点问题
cout<<"x2="<<(-b)/(2*a)<<-sqrt(delta)/(2*a)<<"i"<<endl;
cout<<sqrt(delta)/(2.0*a);
}
}
return 0;
}
第二题:
#include <iostream>
using namespace std;
int main()
{
int a,b,c,n,s;
for(n=100;n<1000;n++)
{
a=n/100;
b=(n%100)/10;
c=n%10;
s=a*a*a+b*b*b+c*c*c;
if(n==s)
cout<<n<<" ";
}
return 0;
}
第三题:
#include <iostream>
using namespace std;
int main()
{
void exchange(int*,int*);
int a,b;
cout<<"please input a and b:"<<endl;
cin>>a>>b;
int *p1=&a,*p2=&b;
cout<<a<<b<<endl;
exchange(p1,p2);
cout<<a<<b<<endl;
return 0;
}
void exchange(int *p1,int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
第一题有点问题,还请高手指教