Khush CP Practical 3S
Khush CP Practical 3S
Methodology:
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
float d,x,x1;
printf(" value of a,b and c for the quadratic equation");
scanf("%d %d %d",&a,&b,&c);
d=b*b-4*(a*c);
x=(-b+sqrt(b*b-4*(a*c)))/2*a;
x1=(-b-sqrt(b*b-4*(a*c)))/2*a;
if(d==0)
{
printf("the roots are real and same");
printf("value of one root is %f",x);
printf("value of second root is %f",x1);
}
else if(d>0)
{
printf("roots are real and different");
printf("value of one root is %f",x);
printf("value of second root is %f",x1);
}
else if(d<0)
{
printf("roots are imaginary");
}
}
Theoritical Principles used:
Use of if and else in case when there are various outcomes,
Input/output:
Practical No: 3(B)
AIM: In an organization, employees are paid on an hourly basis. Clerks are paid 100/hr, Teachers are
paid 200/hr and the principal is paid 400/hr. If the weekly hours exceed 44, then employees should
be paid 2 times their regular pay for the overtime. Write a C program to compute the weekly salary
of the employee and also the program should take care that the employee should not be paid for
hours beyond 50 in a week. Use the best suitable control construct to implement the program.
Methodology:
#include<stdio.h>
#include<math.h>
int main()
{
int hours,job, salary,x;
Methodology:
#include<stdio.h>
main()
{
int X;
printf("Enter the number\n");
scanf("%d",&X);
if (X%10==0)
{
printf("WON IN 0 TURN");
}
else if (X%5==0)
{
printf("WON IN 1 TURN");
}
else
{
printf("IMPOSSIBLE TO WIN");
}
}
Methodology:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
srand(time(NULL));
int t;
t=rand()%100;
int p;
printf("enter the number");
scanf("%d",&p);
if (p==t)
{
printf("you guessed the correct number");
}
else
{
printf("you guessed wrong number");
printf("the number computer generated was %d",t);
}
}
Theoritical Principles Used:
Use of “random” to make a random number and use of null .
Input/output
Practical 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
ofGrade Range of total marks A+ 91-100 A 81-90 B+ 71-80 B 61-70 C+ 51-60 C >40 Fail <40.
Methodology:
#include<stdio.h>
int main ()
{
float TM,CT,TUT,SE,LPW,SEE;
printf("enter marks of class test");
scanf("%f",&CT);
printf("enter marks of tutoriat");
scanf("%f",&TUT);
printf("enter marks of SE");
scanf("%f",&SE);
printf("enter marks of LPW");
scanf("%f",&LPW);
printf("enter marks of SEE");
scanf("%f",&SEE);
TM=(0.12*CT)+(0.12*TUT)+(0.16*SE)+(0.20*LPW)+(0.40*SEE);
printf("%f",TM);
if (91<=TM&& TM<=100)
{
printf("grade is A+");
}
else if (81<=TM&&TM<=90)
{
printf("grade is A");
}
else if (71<=TM&&TM<=80)
{
printf("grade is B+");
}
else if (61<=TM&&TM<=70)
{
printf("grade is B");
}
else if (51<=TM&&TM<=60)
{
printf("grade is c+");
}
else if (TM>=40)
{
printf("grade is C");
}
else if (TM<=40)
{
printf("grade is FAIL");
}
}
Theoritical principles Used :
Use of if ,else, “<=” and “>=” to get a range to give perfect grade
Input/output
CONCLUSION:
FROM THIS PRACTICAL WE LEARNED ABOUT THE PERFECT USE OF IF ELSE FUNCTION TO SEPARATE
DIFFERENT CASES TO SOLVE REAL LIFE PROBLEMS AND MAKE IT EASIER TO ALLOT THE FINAL
SCORES.