Solve Second Order Quadratic Equation : C Program

Computer Science » C Program » Solve Second Order Quadratic Equation 

Program :

#include<stdio.h>
#include<math.h>
 
int main() 
{
   float a, b, c;
   float desc, root1, root2;
 
   printf("nEnter the Values of a : ");
   scanf("%f", &a);
   printf("nEnter the Values of b : ");
   scanf("%f", &b);
   printf("nEnter the Values of c : ");
   scanf("%f", &c);
 
   desc = sqrt(b * b - 4 * a * c);
 
   root1 = (-b + desc) / (2.0 * a);
   root2 = (-b - desc) / (2.0 * a);
 
   printf("nFirst Root : %f", root1);
   printf("nSecond Root : %f", root2);
 
   return (0);
}

Output :

Enter the Values of a : 1
Enter the Values of b : -5
Enter the Values of c : 6
First Root : 3.000000
Second Root : 2.000000
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • C Program ExamplesComputer Science » C Program » C Program Examples "How to print hello, world! using c program ? How to find area of a circle using c program ? How to find smallest element in an array using c program ? You all must have this kind of questions in your mind. Below article will solve this puzzle of yours. Just take a look.”  - Here we have listed all the programs in C programming language, categorised under different progamming concepts like Basic, Area, Mathematical, Number, Array etc. Check the respective category to view all the programs under that category. C Programs - Basic C Programs C Programs - Number Programs C Programs - Area Programs C Programs - Mathematical Programs C Programs - Array Programs C Programs - Electrical Programs C Programs - Pyramid Programs
    Tags: programs, program, computer, science
  • Find Sum of Two Float Numbers : C ProgramComputer Science » C Program » Find Sum of Two Float Numbers Program : [php]#include<stdio.h> int main() { float a, b, sum; printf("Enter two numbers : "); scanf("%f %f", &a, &b); sum = a + b; printf("nSum : %.2f", sum); return(0); }[/php] Output : [php]Enter two numbers : 2.2 3.6 Sum : 5.80[/php]
    Tags: program, computer, science, output, programs
  • Find Factorial of a Number : C ProgramComputer Science » C Program » Find Factorial of a Number Program : [php]#include <stdio.h> int main() { int i, fact = 1, num; printf("Enter the number : "); scanf("%d", &num); if (num <= 0) fact = 1; else { for (i = 1; i <= num; i++) { fact = fact * i; } } printf("nFactorial of %d is : %5d", num, fact); }[/php] Output : [php]Enter the number : 5 Factorial of 5 is : 120[/php]
    Tags: program, computer, science, output, programs
  • Print Alternate Numbers in an Array : C ProgramComputer Science » C Program » Print Alternate Numbers in an Array  Program : [php] int main() { int array[9]; int i; printf("Enter the element of the array : "); for (i = 0; i < 9; i++) scanf("%d", &array[i]); printf("nAlternate elements of the entered array : n"); for (i = 0; i < 9; i += 2) printf( "%dn", array[i]) ; }[/php] Output : [php]Enter the element of the array : 1 2 3 4 5 6 7 8 9 Alternate elements of the entered array : 1 3 5 7 9[/php]
    Tags: program, computer, science, output, programs
  • Swap of Two Numbers using Pointers : C ProgramComputer Science » C Program » Swap of Two Numbers using Pointers  Program : [php]#include <stdio.h> int main() { int x,y,temp,*a,*b; printf("Enter the two numbers : "); scanf("%d%d",&x,&y); printf("nBefore swapping : n x = %dn y = %dn",x,y); a = &x; b = &y; temp = *b; *b = *a; *a = temp; printf("After swapping : n x = %dn y = %dn",x,y); return 0; }[/php] Output : [php]Enter the two numbers : 10 20 Before swapping : x = 10 y = 20 After swapping : x = 20 y = 10[/php]
    Tags: program, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here