#include <stdio.h>
#include <math.h>
main()
{
float a, b, c, x1, x2, q, d, x1r, x2r, x1i, x2i;
printf("Input coefficients of square equation a,b,c:");
scanf("%f %f %f", &a, &b, &c);
d=b*b -4.0*a*c;
if (d > 0)
{
/* results are real numbers */
q = pow (d, 1./2);
x1 = (-b + q)/(2*a);
x2 = (-b - q)/(2*a);
printf ("X1=%f X2=%f\n", x1, x2);
}
else if (d == 0)
{
/* there’s only one result */
x1 = -b/(2*a);
printf ("X1=X2=%f\n", x1);
} else
{
/* results are complex numbers */
q = pow(-d, 1./2);
x1r = -b/(2*a) ;
x2r = x1r;
x1i = q/(2*a);
x2i = -x1i;
printf ("X1 = (%f,%f)\n", x1r, x1i);
printf ("X2 = (%f,%f)\n", x2r, x2i);
}
}
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
0 comments to "DETERMINING ROOTS OF AN EQUATION"
Powered by Blogger.
Blog Archive
-
▼
2011
(50)
-
▼
July
(38)
- INTRODUCTION TO C
- DATA SETS IN C
- DATA TYPES
- VARIABLES
- SIMPLE C PROGRAM
- PROGRAM USING SCANF() AND PRINTF()
- C INSTRUCTIONS
- INTRODUCTION TO DECISION CONTROL STRUCTURES
- IF STATEMENT
- IF STATEMENT PROGRAM
- IF ELSE STATEMENT
- NESTED IF ELSE
- DETERMINING ROOTS OF AN EQUATION
- ELSE IF STATEMENT
- LOGICAL AND ARITHMETIC OPERATORS
- CONDITIONAL OPERATORS
- LOOPS
- THE WHILE LOOP
- The for bend specify things about a bend in a ind...
- EXAMPLE OF FOR LOOP
- NESTING OF LOOPS
- THE ODD LOOP
- THE DO-WHILE LOOP
- BREAK STATEMENT IN C
- THE CONTINUE STATEMENT IN C
- SWITCH STATEMENT IN C
- SIMPLE PROGRAM SHOWING SWITCH STATEMENT
- THE GOTO STATEMENT IN C LANGUAGE
- FUNCTIONS IN C LANGUAGE
- CALLING FUNCTIONS IN C LANGUAGE
- CALL BY REFERENCE IN C LANGUAGE
- POINTERS IN C LANGUAGE
- SIMPLE PROGRAM SHOWING POINTER IN C LANGUAGE
- PROGRAM FOR FUNCTION CALL BY REFERENCE IN C
- SWAPPING OF TWO NUMBERS IN C
- RECURSION IN C LANGUAGE
- FACTORIAL OF A NUMBER WITHOUT RECURSION IN C
- ARRAYS IN C LANGUAGE
-
▼
July
(38)
Post a Comment