Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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


Ïà¹ØÎĵµ£º

CÎļþ²Ù×÷Óëfstream¶ÁÈ¡Îı¾ÎļþµÄЧÂʱȽÏ

Õ⼸ÌìÓÉÓÚÒª¶ÁÈ¡½Ï´óµÄÎı¾Îļþ£¬ËùÒԾͱȽÏÁËÒ»ÏÂÁ½ÕßÖ®¼äµÄЧÂÊÎÊÌâ¡£ ËùÒª¶ÁÈ¡µÄÎı¾Îļþ½á¹¹ÎªÃ¿ÐÐÓÉ5¸öÊý×é³É£¬int int int float int£¬²âÊÔµÄÎļþÓÐ33WÐУ¬´óСΪ9M¡£ÏÖÔÚÒª½«Æä¶Áµ½Ò»¸öcube½á¹¹ÌåÀïÃæÈ¥£¬½á¹¹ÌåÓÐ5¸ö³ÉÔ±±äÁ¿ÓëÖ®¶ÔÓ¦¡£ Á½ÖÖ²Ù×÷µÄ´úÂëÈçÏ start = clock();
    ......

C/C++ÖеĽṹÌå¶ÔÆëÎÊÌâ(ÄÚ´æ¶ÔÆë)

ÓÉÓÚ³ÌÐòÔËÐÐʱռÓõÄÄÚ´æ¹ý´ó£¬ËùÒÔÏë°ì·¨¸ø³ÌÐòÊÝÉí¡£
ÔÚµ÷ÊÔÖз¢ÏֽṹÌåÕ¼ÓõÄsize¾¹È»ºÍÔ¤ÏëµÄ²»Ò»Ñù£¬Ô­À´……
¿´¿´ÏÂÃæ½²µÄ°É£¬¿Ï¶¨»á²»Í÷´Ë¿´Å¶£¡
1,±ÈÈç:
struct{
short a1;
short a2;
short a3;
}A;
struct{
long a1;
short a2;
}B;
sizeof(A)=6, sizeof(B)=8,Ϊʲô£¿
×¢£ºsizeof(sho ......

ÓÃVim´î½¨C/C++¿ª·¢»·¾³

ÀîÈôÀÏÊ¦Ôø¾­Ëµ£ºÊÀ½çÉϵijÌÐòÔ±·ÖÈýÖÖ£¬Ò»ÖÖÊÇÓÃEmacs£¬Ò»ÖÖÊÇÓÃVimµÄ£¬ÆäËüµÄ¹éΪµÚÈýÖÖ¡£ÆäÒâÊÇ˵Èç¹ûÒ»¸ö³ÌÐòÔ±Á½Õß¶¼²»Óõϰ£¬ÄÇ´óµÖÊDz»ÄÜ
¹éΪÈëÁ÷ÕßÐÐÁеġ£¶ÔʹÓÃC/C++µÄÈËÀ´Ëµ£¬ºÜ¶àÈËϲ»¶Emacs£¬¾Ý˵Óë¶ÔStallmanµÄ³ç°ÝÓë°®Îݼ°ÎÚÓйØ;-)¡¡µ±È»£¬EmacsÓëVimËä
È»ÔÚÎı¾±à¼­·½ÃæµÄÐÔÄÜÊǵȼ۵쬵«Ê¹ÓÃÆðÀ´Á½Õ ......

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ºÅ