First program:
You should tell us exactly how it's not working; i.e. input you're entering, output you're expecting, and actual output you're getting.
Also, neatly formatted and indented code is much nicer to read:
Code:
#include <stdio.h>
int main()
{
float a,b,c,x1,x2;
printf("\nenter the coefficient of a,b,c:");
scanf("%f%f%f",&a,&b,&c);
x1=-b+sqrt(b*b-4*a*c)/2*a;
x2=-b-sqrt(b*b-4*a*c)/2*a;
printf("\n-b+sqrt(b*b-4*a*c)/(2a) = %.2f\n",x1);
printf("\n-b-sqrt(b*b-4*a*c)/(2a) = %.2f\n",x2);
return 0;
}
Check your warnings:
Code:
/*
main.c||In function 'main':|
main.c|10|warning: implicit declaration of function 'sqrt'|
main.c|10|warning: incompatible implicit declaration of built-in function 'sqrt'|
||=== Build finished: 0 errors, 2 warnings ===|
*/
You should be including "math.h".
Also, you need to be careful of your input - the quadratic equation could potentially yield an imaginary number.
Originally Posted by
7.12.7.5, paragraph 2
The sqrt functions compute the nonnegative square root of x. A domain error occurs if
the argument is less than zero.
Finally, and this is the most important bit - be very careful that your equation takes order of operations correctly into account. I'd suggest grouping the entire numerator in parathesis, and the entire denominator in parenthesis.
Second program:
Ditto above advice, on asking clear questions and telling us exactly what is wrong.
Also ditto on the neatly formatted and indented code.
Code:
#include<stdio.h>
int main()
{
float C,F,K;
printf("\nenter the temperature in Celsius:");
scanf("%f",&C);
F=9/5*C+32;
K=C+27.15;
printf("\n9/5*C+32 = %.2f\n",F);
printf("\nC+273.15 = %.2f\n",K);
return 0;
}
This line of code is where you want to start looking:
9/5 is integer division, and as such yields a (truncated) integer result. In this case, 9/5 would be equal to 1. If you want a floating point result, at least one of the operands has to be floating point. This could be as simple as changing it to "9.0/5.0",
The Kelvin calculation also has an error, pointed out by CodeMonkey above.
Also if someone could show me the code of a sample chart with 3 arrays it'd be help.(like a mark sheet of a student containing name marks & grade)
I'm not quite sure what you're asking here. Can you clarify?