Custom Search

Monday 21 November 2011

C/ C++ Program to print Quadratic Equation by entering numbers from users, Procedure to print Quadratic Equation with Output


C/ C++ Program to print Quadratic Equation by entering numbers from users, Procedure to print Quadratic Equation with Output

Program:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
printf("Enter the values of a,b,c:\n");
scanf("%f %f %f", &a, &b, &c);
d= b*b - 4*a*c;
printf("discriminant is:%f", d);
if(d<0)
{
printf("\nRoots are Imaginary");
}
else
{
r1= (-b+ sqrt(d))/(2*a);
r2=( -b- sqrt(d))/(2*a);
printf("\n%f %f",r1,r2);
}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the result

No comments:

Post a Comment

Laptops