Skip to content

Instantly share code, notes, and snippets.

@bykalim
Created April 22, 2017 15:39
Show Gist options
  • Save bykalim/966462ea5e202dcd848118a544256fb1 to your computer and use it in GitHub Desktop.
Save bykalim/966462ea5e202dcd848118a544256fb1 to your computer and use it in GitHub Desktop.
CA Programming Lab1: at RUPP
// កម្មវិធីដោះស្រាយ​ សមីការដឺក្រេទី​២.c
// written by By Kalim
#include <stdio.h>
#include <math.h>
int main(){
float Delta=0;
float a=0;
float b=0;
float c=0;
float d=0;
float x[2];
char choice;
printf("+-------------------------------------------------------+\n");
printf("| Math Solver: The Quadratic Formula |\n");
printf("| ax^2 + bx + c = d |\n");
printf("+-------------------------------------------------------+\n");
printf("| 1. Set Value for a ,b ,c ,d |\n");
printf("+-------------------------------------------------------+\n");
printf(" a = ");
scanf("%f",&a);
printf(" b = ");
scanf("%f",&b);
printf(" c = ");
scanf("%f",&c);
printf(" d = ");
scanf("%f",&d);
printf(" ==> %-.2f x^2 %+-.2fx %+-.2f = %+-.2f\n",a,b,c,d);
Delta = pow(b,2)-4*a*(c-d);
if (Delta<0) {
x[0] = ((-1)*b)/(2*a);
x[1] = ((-1)*b)/(2*a);
printf("+-------------------------------------------------------+\n");
printf("| 2. Result Δ < 0 |\n");
printf("+-------------------------------------------------------+\n");
printf(" Δ = %.2f * i^2\n",Delta);
Delta = -Delta;
printf(" x[1] = %.2f %.2fi\n",x[0],sqrt(Delta));
printf(" x[2] = %.2f %.2fi\n",x[1],-sqrt(Delta));
}
else if(Delta==0) {
x[0] = ((-1)*b)/(2*a);
printf("+-------------------------------------------------------+\n");
printf("| 2. Result Δ = 0 |\n");
printf("+-------------------------------------------------------+\n");
printf(" Δ = %.2f\n",Delta);
printf(" x[1] = x[2] = %.2f\n",x[0]);
}
else
{
x[0] = ((-1)*b+sqrt(Delta))/(2*a);
x[1] = ((-1)*b-sqrt(Delta))/(2*a);
printf("+-------------------------------------------------------+\n");
printf("| 2. Result Δ > 0 |\n");
printf("+-------------------------------------------------------+\n");
printf(" Δ = %.2f\n",Delta);
printf(" x[1] = %.2f\n",x[0]);
printf(" x[2] = %.2f\n",x[1]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment