8 Mart 2010 Pazartesi

Ikinci Dereceden Denklemlerin Köklerini Bulan C Kodu

//www.ethemsulan.com
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
void denk_iki_derece(float a,float b,float c);
    float x,y,z;
printf("x in kat sayisi,y in kat sayisi,z in kat sayisini girin\n");
    scanf("%d %d %d",&x,&y,&z);
    denk_iki_derece(x,y,z);
  system("PAUSE");	
  return 0;
}  
void denk_iki_derece(float a,float b,float c){
   float delta,kok1,kok2,g;
   delta=b*b-4*a*c;
  if(delta<0){
printf("\ndenklemin gercek koku yok\n");
  return;
  }
  else if(delta==0){
   kok1=-b/(2*a);
printf("\nkok1=kok2=%8.3f\n",kok1);
    return;     
}else{
   g=exp(0.5*log(delta));
   kok1=(-b+g)/(2*a);
   kok2=(-b-g)/(2*a);
   printf("\nkok1=%8.3f",kok1);
    printf("\nkok2=%8.3f",kok2);     
         }
         }

Hiç yorum yok:

Yorum Gönder