Lab File-Format
Lab File-Format
B.Tech-First Year
Semester-I
Lab File
PROGRAMMING FOR PROBLEM SOLVING
(BCS-151)
DEPARTMENT: BRANCH:
LAB PROGRAMS INDEX
Lab
OBJECTIVES DATE MARKS SIGN.
No.
i) Money’s Interest
1
ii) Roots of Quadratic Equation
i) Armstrong in a Range
3
ii) Check Prime
i) Linear Searching
6
ii) Binary Searching
i) Bubble sort
7
ii) Matrix Multiplication
i) Anagram Strings
8
ii) Sorting N Strings
Input Format:
A line contains space separated values of three coefficients a, b, c from the equation: ax2 + bx + c = 0
Output Format:
First line will tell property of roots: "REAL AND DISTINCT" or "REAL AND EQUAL" or "IMAGINARY
ROOTS" Second line will show space separated values of both roots.
PROGRAM:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a, b, c;
float D, r1,r2, real, imag;
scanf("%d %d %d",&a,&b,&c);
D=b*b-4.0*a*c;
if (D>0)
{
printf("REAL AND DISTINCT\n");
r1= (-b+sqrt(D))/(2*a);
r2= (-b-sqrt(D))/(2*a);
printf("%.2f %.2f",r1 , r2);
}
else if (D==0)
{
printf("REAL AND EQUAL\n");
r1 = r2 = (float)-b/(2*a);
printf("%.2f %.2f", r1, r2);
}
else
{
printf("IMAGINARY ROOTS\n");
real= (float)-b/(2*a);
imag = (float)sqrt(-D)/(2*a);
printf("%.2f+%.2f i %.2f-%.2f i", real, imag, real, imag);
}
return 0;
}