1: #include<stdio.h>
2: #include<conio.h>
3: #include<math.h>
4: #include<stdlib.h>
5: void roots(float a,float b,float c,float *r1,float *r2);
6: void main()
7: {
8: float a,b,c,root1,root2;
9: printf("Enter the coefficient of a,b,c:\n");
10: scanf("%f%f%f",&a,&b,&c);
11: roots(a,b,c,&root1,&root2);
12: printf("Roots of the equation are %.2f and %.2f\n",root1,root2);
13: getch();
14: }
15: void roots(float a,float b,float c,float *r1,float *r2)
16: {
17: float d;
18: d=b*b-4.0*a*c;
19: if(d<0)
20: {
21: printf("no real root\n");
22: getch();
23: exit(0);
24: }
25: else
26: *r1=(-b+sqrt(d))/(2.0*a);
27: *r2=(-b-sqrt(d))/(2.0*a);
28: }
No comments:
Post a Comment