ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
program to find the roots of a quadratic equation
 Question Submitted By :: Nithya
I also faced this Question!!     Rank Answer Posted By  
 
  Re: program to find the roots of a quadratic equation
Answer
# 1
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void main()
{
float a,b,c,x1,x2,disc;
clrscr();
printf("Enter the co-efficients\n");
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;/*to find discriminant*/
if(disc>0)/*distinct roots*/
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("The roots are distinct\n");
exit(0);
}
if(disc==0)/*Equal roots*/
{
x1=x2=-b/(2*a);
printf("The roots are equal\n");
printf("x1=%f\nx2=%f\n",x1,x2);
exit(0);
}
x1=-b/(2*a);/*complex roots*/
x2=sqrt(fabs(disc))/(2*a);
printf("The roots are complex\n");
printf("The first root=%f+i%f\n",x1,x2);
printf("The second root=%f-i%f\n",x1,x2);
getch();
}
 
Is This Answer Correct ?    43 Yes 11 No
Dhananjay
 
  Re: program to find the roots of a quadratic equation
Answer
# 2
Lets i see first
 
Is This Answer Correct ?    19 Yes 3 No
Pankaj
 
 
 
  Re: program to find the roots of a quadratic equation
Answer
# 3
//program to find roots of given equation
#include<stdio.h>
#include<math.h>
void main()
{
 int a,b,c;
 float d,p,q,r,s;
 printf("\n\n Enter the values of a,b,c")
 scanf("%d%d%d",&a,&b,&c);
 d=(b*b)-(4*a*c);
 if(d=0)
 {
  printf("\n The roots are real and equal");
  p=(-b)/(2*a);
  q=(-b)/(2*a);
  printf("\n The roots of the equation are %f,%f",p,q);
 }
 if(d>0)
  {
   printf("\n The roots are real and distinct");
   p=((-b)+sqrt((b*b)-(4*a*c)))/(2*a);
   q=((-b)-sqrt((b*b)-(4*a*c)))/(2*a);
   printf("\n The roots of the equation are %f,%f",p,q);
  }
 if(d<0)
  {
   printf("\n The roots are imaginary");
   r=(-b)/(2*a);
   s=(sqrt((4*a*c)-(b*b)))/(2*a);
   printf("\n The roots of the equation are
p=%f=%fi,q=%f-%fi",r,s,r,s);
  }
}
 
Is This Answer Correct ?    13 Yes 1 No
Pratibha
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { extern int i; i=20; printf("%d",i); }  1
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }  1
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }  1
main() { printf("\nab"); printf("\bsi"); printf("\rha"); }  1
main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O HCL2
main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }  1
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!  7
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }  1
void main() { int i=5; printf("%d",i++ + ++i); }  1
void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }  1
main() { show(); } void show() { printf("I'm the greatest"); }  1
main() { int c=- -2; printf("c=%d",c); }  1
main() { int i=5; printf(“%d”,i=++i ==6); }  1
How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.  1
main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }  1
main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5 HCL1
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }  1
write a program to count the number the same (letter/character foreg: 's') in a given sentence.  1
What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;  1
struct aaa{ struct aaa *prev; int i; struct aaa *next; }; main() { struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x); }  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com