Lab Practical 3
Lab Practical 3
Lab Practical 3
Practical no.:3(a)
Aim: Write a program to take the values for A, B, C of a
quadratic equation
A∗ X2+B∗ X+C=0 and then find all the roots of the
equation. It is guaranteed
that A≠ 0 and that the equation has at least one real root.
Methodology followed:
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,x;
float x1,x2,d;
printf("a,b,c are coefficients of quadratic equation");
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
printf("Enter the value of c:");
scanf("%d",&c);
d=b*b-4*a*c;
printf("\nThe value of discriminant is %.2f",d);
if(d<0)
{
printf("\nThe quadratic equation is imaginary hence has no real
roots.");
}
else if(d==0)
{
printf("\nThe quadratic equation has 2 real and equal roots"); x=-b/2*a;
}
else
{
printf("\nThe quadratic equation has 2 real and distinct roots"); x1=(-
b+sqrt(d))/2*a;
x2=(-b-sqrt(d))/2*a;
printf("\nThe roots are%.2f and %.2f",x1,x2);
}
}
Output:
Practicle no.:3(b)
Output:
Practicle no.:3(c)
Aim: Ajay and Amit are playing a game with a number X. In one
turn, they
1,2,3,4
can multiply X by 2. The goal of the game is to make X
divisible by 10. Write
a C program to find the number of turns necessary to win the
game (it may be
possible to win in zero turn, 1 turn or it might be
impossible (-1 turns)).
Methodology followed:
#include<stdio.h>
int main()
int x;
scanf("%d",&x);
if(x%10==0)
else if(x*2%10==0)
else
Output:
Practicle no.:3(d)
Aim: Write a program to implement a simple number guessing
game.
Program should generate an integer randomly and ask the user
to guess the
integer. Based on the number guessed, it should display the
appropriate message (correct or incorrect).
Methodology followed:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
int a,b;
srand(time(0));
a=rand()%10;
scanf("%d",&b);
if(a==b)
else
{
printf("You lost the game");
printf("\nThe correct answer is %d",a);
Output:
Practicle no.:3(e)
Aim: Write a C program to find the grade of a student based
on the
following policy.
Class test: 12% weightage, Tutorial-12%, SE:16%,
LPW:20%, SEE:40%.
Grade is decided based on the below range of total marks.
Grade Range of total
marks
A+ 91-100
A 81-90
B+ 71-80
B 61-70
C+ 51-60
C >40
Fail <40
Methodology followed:
#include<stdio.h>
int main()
float ct,tut,se,see,total,lpw,a,b,c,d,e;
scanf("%f",&tut);
scanf("%f",&se);
printf("Enter
marks of LPW:");
scanf("%f",&lpw);
a=12*ct/100;
b=12*tut/100;
c=16*se/100;
d=40*see/100;
e=20*lpw/100;
total=(a+b+c+d+e);
if(total>=90)
printf("You have
A+ grade!"); }
else
if(total>=80&&tot
al<90) {
printf("You have
A grade!"); }
else
if(total>=70&&tot
al<80) {
printf("You have
B+ grade!"); }
else
if(total>=60&&tot
al<70) {
printf("You have
B grade!"); }
else if(total>=50&&total<60)
{
else if(total>=40&&total<50)
else
Output: