易截截图软件、单文件、免安装、纯绿色、仅160KB

编程实现一元二次方程的解 ax^2+bx+c=0

#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
double a,b,c;
double delta;
double x1,x2;
cout<<"Please input a,b,c:"<<endl;
cin>>a>>b>>c;
if(cin.fail())
{
cout<<"Error:bad input!";
return 1;
}
delta=b*b-4*a*c;
if(delta>0)
{
cout<<"The Equation has two roots:"<<endl;
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
cout<<"x1="<<x1<<"\n"
<<"x2="<<x2<<"\n";
}
if(delta==0)
{
cout<<"The Equation has two equal roots:"<<endl;
x1=(-b+sqrt(delta))/(2*a);
cout<<"x1=x2="<<x1<<endl;
}

if(delta<0)
{
cout<<"The Equation has two virtual roots:"<<endl;
cout<<"x1="<<(-b)/(2*a)<<"+"<<sqrt(-delta)/(2*a)<<"i"<<endl;
cout<<"x2="<<(-b)/(2*a)<<"-"<<sqrt(-delta)/(2*a)<<"i"<<endl;
}
system("pause");
return 0;
}

实现算法:
 
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int sgn(int m)
{
if(m>=0)
return 1;
else return -1;
}
int _tmain(int argc, _TCHAR* argv[])
{
double a,b,c;
double delta;
double q;
double x1,x2;
cout<<"Please input a,b,c:"<<endl;
cin>>a>>b>>c;
delta=b*b-4*a*c;
if(delta>0)
{
cout<<"The equation has two roots:"<<endl;
q=-(b+sgn(b)*sqrt(delta))/2.0;

x1=q/a;
x2=c/q;

cout<<fixed;
cout<<"x1="<<x1<<"\n"
<<"x2="<<x2<<endl;
}
if(delta==0)
{
cout<<"The equation has two equal roots:"<<endl;
q=-(b+sgn(b)*sqrt(delta))/2.0;

x1=q/a;
cout<<"x1=x2="<<x1<<endl;
}
if(delta<0)
{
cout<<"Error!"<<endl;
return 1;
}
system("pause");
retur


相关文档:

VB/C++/C#串口通讯源代码【附详细注释】


VB
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
    MSComm1.CommPort = i1
    MSComm1.PortOpen = True
    MSComm1.InputMode = comInputModeBinary
    MSComm1.InBufferCount = 0
& ......

Delphi 与 C/C++ 数据类型对照表

Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......

Python 中的函数调用(类似c中的使用函数入口地址)

def login():
    print 'login'
def logout():
    print 'logout'
controllers = {
'in': login,                              ......

C/C++程序员应聘常见面试题深入剖析

 2.找错题
  试题1:
void test1()
{
 char string[10];
 char* str1 = "0123456789";
 strcpy( string, str1 );
}
  试题2:
void test2()
{
 char string[10], str1[10];
 int i;
 for(i=0; i<10; i++)
 {
  str1[i] = 'a';
 }
 strcpy( string, str1 );
}
  试题3:
void te ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号