PDA

View Full Version : ax2+bx+c=0



lien3001vl2a
20-05-2009, 22:15
toi cho source nay chay trong visual studio 2008 ne:
nhung ra ket qua sai,khong biet sua.

// phuong trinh ax+bx+c=0 : main project file.

#include "stdafx.h"
#include<stdio.h>
#include<math.h>
int main()
{
float delta;
float a;
float b;
float c;
float x1;
float x2;
printf("enter a : ");
scanf_s("%f",&a);
printf("enter b : ");
scanf_s("%f",&b);
printf("enter c : ");
scanf_s("%f",&c);
delta=b*b-(4*a*c);
if (delta<0)
{
printf("phuong trinh vo nghiem!\n");

getchar();
if
(delta==0)

x1=-b/(2*a);
printf("phuong trinh co mot nghiem !\n");
printf("x1=x2=%f\n",x1);
getchar();
if
(delta>0)

x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("\nX1=%f",x1);
printf("\nX2=%f\n",x2);
getchar();
}

}

ngocthanh03
20-05-2009, 23:03
#include "stdafx.h"
#include<stdio.h>
#include<math.h>
int main()
{
float delta;
float a;
float b;
float c;
float x1;
float x2;
printf("enter a : ");
scanf_s("%f",&a);
printf("enter b : ");
scanf_s("%f",&b);
printf("enter c : ");
scanf_s("%f",&c);
delta=b*b-(4*a*c);
if (delta<0)
{
printf("phuong trinh vo nghiem!\n");

getchar();}
if
(delta==0){

x1=-b/(2*a);
printf("phuong trinh co mot nghiem !\n");
printf("x1=x2=%f\n",x1);
getchar();}
if
(delta>0){

x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("\nX1=%f",x1);
printf("\nX2=%f\n",x2);
getchar();}
}


Thử lại xem co chạy ko nhé!:D

lien3001vl2a
21-05-2009, 07:55
// phuong trinh ax2+bx+c=0 : cai nay chay duoc trong visúal studio 2008

#include "stdafx.h"
#include<stdio.h>
#include<math.h>
#include<iostream>
int main()
{
float delta;
float a;
float b;
float c;
float x1;
float x2;
printf("enter a : ");
scanf_s("%f",&a);
printf("enter b : ");
scanf_s("%f",&b);
printf("enter c : ");
scanf_s("%f",&c);
delta=b*b-(4*a*c);
if (delta<0)
{
printf("phuong trinh vo nghiem!\n");

system("pause");
}
if
(delta==0){

x1=-b/(2*a);
printf("phuong trinh co mot nghiem !\n");
printf("x1=x2=%f\n",x1);
system("pause");
}
if
(delta>0){

x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("phuong trinh co hai nghiem phan biet:\n");
printf("\nX1=%f\n",x1);
printf("\nX2=%f\n",x2);
system("pause");
}

}