Jump to content
G3ner1c

Problema c++

Recommended Posts

Posted

#include<iostream>

using namespace std;

int main()

{

int a,b,c;

float d,x,y;

cout<<"a= ";cin>>a;

cout<<"b= ";cin>>b;

cout<<"c= ";cin>>c;

d=b*b-4*a*c;

if(d>0)

{

x=(-b+(SQRTd))/2*a;

y=(-b-(SQRTd))/2*a;

cout<<"x= "<<x;

cout<<"y= "<<y;

}

else

if(d==0)

{

x==-b/2*a;

cout<<"x= "<<x;

}

else

if(d<0)

{cout<<"complex";}

}

Imi spune ca am o eroare la "x=(-b+(SQRTd))/2*a;".Nu inteleg ce greseala este. :|

Posted

Asta e ultima :))

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int a,b,c;

float d,x1,x2,x;

cout<<"a= ";cin>>a;

cout<<"b= ";cin>>b;

cout<<"c= ";cin>>c;

d=b*b-4*a*c;

Switch(d)

{

case d==0:

x=-b\2*a;

cout<<"x= "<<x;break;

case d<0:

cout<<"Solutia e nr complex";break;

default:x1=(-b+(sqrt(d)))/2*a; x2=(-b-(sqrt(d)))/2*a;

cout<<"x1= "<<x1;

cout<<"x2= "<<x2;

}

}

Vreau sa tranform ala de mai sus, sa folosesc case in loc de if.Ce nu e corect?

Posted (edited)

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int a,b,c;

float d,x1,x2,x;

cout<<"a= ";cin>>a;

cout<<"b= ";cin>>b;

cout<<"c= ";cin>>c;

d=b*b-4*a*c;

if(d==0)

{

x=-b/2*a;

cout<<"X="<<x;

}

else if(d<0)

cout<<"Solutia este nr. complex";

else

{

x1=(-b+(sqrt(d)))/2*a;

x2=(-sqrt(d))/2*a;

cout<<"x1= "<<x1;

cout<<"x2= "<<x2;

}

}

Ce nu e corect?

**Nu poti face comparatii in switch gen : a<4 .

**Nu poti pune intr-un switch numere reale, doar intregi.

Edited by dekeeu

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...