1. ## Creating this formula

So I need to create this calculation in a program. Yes this is HW but I am having the utter most difficult time with this. I just need some help understanding why I can't get this to work.

Now honestly, I am very terrible with math and when I saw this equation, be honest, don't know how to even begin solving.

Any help would be much appreciated. This is the code I have thus far. The formula I need to create is below.

Note: variable a,b,c require user input.

Code:
```#include <stdio.h>
#include <math.h>

main()
{
float a, b, c;
float neper, powNeper, solution;
float e = 2.71828, pi = 3.1415926;

printf("\nThis program will calculate 1/2*sqrt(pi/a)*neper number to the (b^2-4ac)/4a power");
printf("\nwhere variables a-c are inputed by you.");
printf("\nNote: Pi=3.1415926 (approximately), Neper Number=2.71828 (approximately)");

printf("\n\na = ");
scanf("%f", &a);
fflush(stdin);
printf("\nb = ");
scanf("%f", &b);
fflush(stdin);
printf("\nc = ");
scanf("%f", &c);

b = pow(b, 2);
powNeper = (b - (4 * a*c)) / (4 * a);
neper = pow(e, powNeper);

solution = (1 / 2) * (sqrt(pi / a)) * neper;

printf("/n%.5f", solution);

getch();
}```

2. Code:
``` #include <stdio.h>
#include <math.h>

main()
{
float a, b, c;
float neper, powNeper, solution;
float e = 2.71828, pi = 3.1415926;

/* printf("\nThis program will calculate 1/2*sqrt(pi/a)*neper number to the (b^2-4ac)/4a power");
printf("\nwhere variables a-c are inputed by you.");
printf("\nNote: Pi=3.1415926 (approximately), Neper Number=2.71828 (approximately)");
*/

printf("\n\na = ");
scanf("%f", &a);

printf("\nb = ");
scanf("%f", &b);

printf("\nc = ");
scanf("%f", &c);

neper =( b * b - 4 * a * c ) / (4*a);
powNeper = pow(e,neper);

solution = sqrt(pi /(float)a) * 0.5 * powNeper;

printf("\n%f",solution);

return 0;
}```
i changed a little bit, i deleted the fflush that i do not know. The code is working i think,try this one. I think the reason is that in your code 1/2 produces zero. instead (float)1/2 -->produces without any loss.

3. you better of using doubles - you get noting here by using floats except increasing the calculation errors

4. Thanks for the solutions guys. The (float)1/2 helped actually start showing numbers. I was wondering though. As complex as it may be in terms of setting up, could someone show me how I would be able to write the full equation just in one line. If you notice my original code, I went ahead and determined what the exponent was for 'e' before writing up the final calculation.

Code:
```b = pow(b, 2);
powNeper = (b - (4 * a*c)) / (4 * a);
neper = pow(e, powNeper);```
Instead of adding all this to the source code, how could I write it out that i could just include it in the 'solution' calculation?

Also, I have to show the solution in scientific notation which i figured out is %e, but say i use the values: a=10, b=15, and c=20, i get the right answer (1.60e-007) but is there a way to format that even further to eliminate the '0s' in the -007?

Much appreciated again for the help.

5. Originally Posted by raven2313
Also, I have to show the solution in scientific notation which i figured out is %e, but say i use the values: a=10, b=15, and c=20, i get the right answer (1.60e-007) but is there a way to format that even further to eliminate the '0s' in the -007?
According to one source I found regarding the %e format specifier in printf:
The exponent always contains at least two digits; if the value is zero, the exponent is 00. In Windows, the exponent contains three digits by default, e.g. 1.5e002, but this can be altered by Microsoft-specific _set_output_format function.
Which seems to be echoed in another post here.

So, assuming you are indeed on a Windows system maybe you could use the suggestion. Otherwise it looks like you can't do it... except maybe by printing it to a string and then finding/deleting those extra 0's and then printing the modified string.