Bài 63: Giải phương trình bậc nhất một ẩn: ax + b = 0
//========================================// Cach 1
#include <stdio.h>
#include <conio.h>
void main()
{
float a,b;
printf("a = ");
scanf("%f", &a);
printf("b = ");
scanf("%f", &b);
if (a == 0)
if (b == 0)
printf("Phuong trinh vo so nghiem");
else
printf("Phuong trinh vo nghiem");
else
{
float x = (float)-b/a;
printf("x = %f", x);
}
}
//========================================
//Cach 2
/*
#include <stdio.h>
#include <conio.h>
void GiaiPT(float,float);
void main()
{
float a,b;
printf("a = ");
scanf("%f", &a);
printf("b = ");
scanf("%f", &b);
GiaiPT(a,b);
}
void GiaiPT(float c, float d)
{
if (c == 0)
if (d == 0)
printf("Phuong trinh co vo so nghiem");
else
printf("Phuong trinh vo nghiem");
else
{
float x = -d/c;
printf("x = %f", x);
}
}
*/
No comments:
Post a Comment