Показать сообщение отдельно

  #4  
Старый 02.10.2008, 23:20
VIP
Участник форума
Регистрация: 29.12.2004
Сообщений: 105
Провел на форуме:
89596

Репутация: 21
По умолчанию

Почему он не правильно вычисляет t1 и t2?

Код:
# include <stdio.h>
# include <math.h>
int main() {
    float a;
    float b;
    float c;
    float d;
    float t;
    float t1;
    float t2;
    float x1;
    float x2;
    float x1t1;
    float x2t1;
    float x1t2;
    float x2t2;
    printf("Enter a, please: ");
    scanf("%f", &a);
    printf("Enter b, please: ");
    scanf("%f", &b);
    printf("Enter c, please: ");
    scanf("%f", &c);
    d=pow(b,2)+4*a*c;
    if (d<0) {
             printf("D<0 => this equation has not radicals");
    } else if (d=0) {
             t=-b/2*a;
             if (t<0) {
                        printf("X^2 < 0 => this equation has not radicals");
             } else {
                        x1=pow(t,0.5);
                        x2=-pow(t,0.5);
                        printf("X1 = %f", x1);
		                printf("X2 = %f", x2);
             }
    } else {
             t1=(-b+pow(d,0.5))/2*a;
	         t2=(-b-pow(d,0.5))/2*a;
	         if (t1>=0 and t2>=0) {
                x1t1=pow(t1,0.5);
		        x2t1=-pow(t1,0.5);
		        x1t2=pow(t2,0.5);
		        x2t2=-pow(t2,0.5);
		        printf("X1 = %f", x1t1);
		        printf("X2 = %f", x2t1);
		        printf("X3 = %f", x1t2);
		        printf("X4 = %f", x2t2);
          } else if (t1>=0 and t2<0) {
                x1t1=pow(t1,0.5);
		        x2t1=-pow(t1,0.5);
		        printf("X1 = %f", x1t1);
		        printf("X2 = %f", x2t1);
          } else if (t1<0 and t2>=0) {
                x1t2=pow(t2,0.5);
		        x2t2=-pow(t2,0.5);
		        printf("X1 = %f", x1t2);
		        printf("X2 = %f", x2t2);
          } else if (t1<0 and t2<0)
                printf("This equation has not radicals");
          }
}

Последний раз редактировалось VIP; 02.10.2008 в 23:23..
 
Ответить с цитированием