1: #include<stdio.h>
2: #include<conio.h>
3: #include<math.h>
4: #include<stdlib.h>
5: void readdata();
6: void checkdata();
7: void showroots();
8: float a,b,c,delta,root1,root2;
9: void main()
10: {
11: readdata();
12: checkdata();
13: showroots();
14: getch();
15: }
16: void readdata()
17: {
18: printf("\nEnter co-eff of a,b,c:");
19: scanf("%f%f%f",&a,&b,&c);
20: }
21: void checkdata()
22: {
23: if(a==0)
24: {
25: printf("\nRoots cannot be found");
26: exit(0);
27: }
28: delta=b*b-4.0*a*c;
29: if(delta<0)
30: {
31: printf("\nRoots are imaginary");
32: exit(0);
33: }
34: }
35:
36: void showroots()
37: {
38: root1=(-b+sqrt(delta))/(2*a);
39: root2=(-b-sqrt(delta))/(2*a);
40: printf("\nroot1=%f root2=%f",root1,root2);
41: }
No comments:
Post a Comment