( Giải phương trình bậc hai dùng ngôn ngữ C )
Doing all of the calculation in only 1 code line for solving quadratic equation
How boring it is, isn't it :D
#include
#include
#include
void main()
{
double a,b,c;
printf("=======================================\n=============== GPTB 2 ================\n=======================================\nNhap du lieu a,b,c cua phuong ax^2 + bx + c = 0\n");
printf("Nhap a = "); scanf("Nhap a = %lf",&a);
printf("\n");
printf("Nhap b = "); scanf("%lf",&b);
printf("\n");
printf("Nhap c = "); scanf("%lf",&c);
printf("\n");
(a == 0)?((c==0)?((b == 0)?printf("PT vo so nghiem\n"):printf("PT vo nghiem")):((b == 0)?printf("PT vo nghiem\n"): printf("PT co 1 nghiem: %lf",-c/b))):((c != 0) ? ((b == 0) ?(( c< 0) ?printf("PT co nghiem: x = +/-%lf",sqrt(-c/a)):printf("PT vo nghiem\n")):(((b*b - 4*a*c) > 0) ?printf("PT co 2 nghiem: \nx1 = %lf \nx2 = %lf\n",(-b + sqrt(b*b - 4*a*c))/(2*a),(-b-sqrt(b*b - 4*a*c))/(2*a)):printf("PT vo nghiem\n"))):((b == 0)?printf("PT co nghiem x=0"):printf("PT co 2 nghiem x1 = 0 and x2 = %lf",-b/a)));
}
Doing all of the calculation in only 1 code line for solving quadratic equation
How boring it is, isn't it :D
#include
#include
#include
void main()
{
double a,b,c;
printf("=======================================\n=============== GPTB 2 ================\n=======================================\nNhap du lieu a,b,c cua phuong ax^2 + bx + c = 0\n");
printf("Nhap a = "); scanf("Nhap a = %lf",&a);
printf("\n");
printf("Nhap b = "); scanf("%lf",&b);
printf("\n");
printf("Nhap c = "); scanf("%lf",&c);
printf("\n");
(a == 0)?((c==0)?((b == 0)?printf("PT vo so nghiem\n"):printf("PT vo nghiem")):((b == 0)?printf("PT vo nghiem\n"): printf("PT co 1 nghiem: %lf",-c/b))):((c != 0) ? ((b == 0) ?(( c< 0) ?printf("PT co nghiem: x = +/-%lf",sqrt(-c/a)):printf("PT vo nghiem\n")):(((b*b - 4*a*c) > 0) ?printf("PT co 2 nghiem: \nx1 = %lf \nx2 = %lf\n",(-b + sqrt(b*b - 4*a*c))/(2*a),(-b-sqrt(b*b - 4*a*c))/(2*a)):printf("PT vo nghiem\n"))):((b == 0)?printf("PT co nghiem x=0"):printf("PT co 2 nghiem x1 = 0 and x2 = %lf",-b/a)));
}
Click on the image to enlarge your view :)
No comments:
Post a Comment