Join Us on Facebook Follow us on Twitter Add to Circles

Sunday, December 28, 2014

Ex4- សរសេកម្មវិធីដោះស្រាយសមីការដឺក្រទី២៖ ax2 + bx + c = 0


- សរសេកម្មវិធីដោយប្រើអនុគមន៍

- បង្កើតអនុគមន៍ ចំនួន២ ដែល នៅពេល

a=0 នោះវានឹងហៅអនុគមន៍ដែលមានមុខ 
ងារដោះស្រាយ bx + c = 0 តែបើ a!=0 

និងវានឹងហៅអនុគមន៍ដែលមានមុខងារដោះ 
ស្រាយសមីការដឺក្រទី២៖ ax2 + bx + c = 0








Code
#include<stdio.h>
#include<conio.h>
#include<math.h>
float a,b,c,x1,x2,x,delta;
void fun()
{
 if (b==0)
            printf("canot do!");

    else
    {
            x=-c/b;
            printf("x=%f",x);
    }
}
void fun1()
{
 delta=(b*b)-4*a*c;
  if (delta==0)
  {
            x1=-b/(2*a);
            printf("x1=x2=%.2f",x1);
  }
  else
  {
            if (delta<0)
            {
            printf("No root!");
            }
            else
            {
            x1=(-b+sqrt(delta))/(2*a);
            x2=(-b-sqrt(delta))/(2*a);
            printf("x1=%f x2=%f",x1,x2);
  }        }
}
void main()
{clrscr();
printf("Input a:");scanf("%f",&a);
printf("Input b:");scanf("%f",&b);
printf("Input c:");scanf("%f",&c);
if(a==0)
 fun();
else
 fun1();
getch();
}

No comments:

Post a Comment