Declare it GLOBAL

Loading...

Search! HigherThanGetche!

Saturday, September 5, 2009

C: DOUBLE and WHILE: Quadratic Formula

For this entry I would be sharing a program that would utilize the QUADRATIC formula.

DOUBLE and a simple WHILE statement is present in this program.

This program also passes values to an existing function (outside main)

I hope these codes would help any student or aspiring programmer. I believe that C is the most basic of all programming languages - you can't learn other languages unless you understand the logic and flow of C.

#include <stdio.h>
#include <math.h>


quadratic(double x, double y, double z)
{
double first, second;
first = (-y+sqrt((y*y)-4*x*z))/(2*x);
second = (-y-sqrt((y*y)-4*x*z))/(2*x);
printf( "%f %f\n", first, second );
getche();
return 0;
}

main()
{
double a, b, c;

while( 1 ) //this while loop states that this loop would always run while the operation is true.
{
printf("Input value a:\n");
scanf( "%f", &a );
if(a>0) printf("input values b and c");
scanf( "\n%f", &b );
scanf( "\n%f", &c );

quadratic( a, b, c );
}
}

0 comments:

Post a Comment