0% found this document useful (0 votes)
11 views10 pages

Khush CP Practical 3S

Uploaded by

24itp029
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

Khush CP Practical 3S

Uploaded by

24itp029
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Date: 10/09/24

Roll No. and Name: 24ITE067 and KHUSH BHATT


Course Code and Name: 1CS501 Computer Programming
Practical No: 3(A)
AIM: Write a program to take the values for A, B, C of a quadratic equation A∗ X 2+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

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;

printf("what is the job profile");


printf("\n(clerk=2 \nteachers=3 \nprincipal=4)\n");
scanf("%d",&job);
printf("how many hours of work done : ");
scanf("%d",&hours);
printf("worked for %d hours",hours);
if(job==2)
{
printf("as a clerk");
x=100;
}
else if (job==3)
{
printf("as a teacher");
x=200;
}
else
{
printf("as a principal");
x=400;
}
if(hours>50)
{
salary=x*hours+2*x*6;
}
else if(44<=hours<=50)
{
salary=x*hours+(hours-44)*2*x;
}
else
{
salary=x*hours;
}
printf("\nFINAL SALARY IS : %d",salary);
}

Theoritical Principles used:


Use of if, else if , else in multiple scenarios and taking range for particular cases.
Input/output:
Practical 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:
#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");
}
}

Theoritical Principles used:


Use of % symbol known as modulus to solve a scenario,
Practical 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:
#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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy