All 16 Combined Practical File
All 16 Combined Practical File
PRACTICAL
OBJECTIVE INITIALS
NO.
Write a program that prints text of four
lines consisting of characters, integers
1.
and floating point values using printf()
statement.
Write a program that converts
temperature in Fahrenheit into
2.
temperature in Celsius.
(Celsius = 5/9 * Fahrenheit -32)
Write a program that finds the area of
triangle (Area = 0.5 * base * height),
3.
area of circle (Area = 𝜋𝑟 2 ) and volume
of sphere (Volume = 4/3 * 𝜋𝑟 3 )
Write a program to print a statement
4.
using printf() and scanf() statements.
Write a program that uses getchar()
statement to enter the value for a,b,c
5.
variables and use putchar() statement to
display it on screen.
Write a program that checks whether the
6.
entered year is a leap year or not.
Write a program to check if a person is
7.
eligible to vote or not.
Write a program that inputs the cost of
8. any item and if cost is greater than
50,000, 5% tax is added to it .
Write a program that asks income and
9. number of dependents. If number of
dependents is greater than 5 then no
income tax is added otherwise 8% tax is
applied to income amount.
Write a program that uses if-else ladder
10. to add, subtract , multiply and divide two
numbers.
Write a program to print days of week
11.
using switch-case statement.
Write a program inputs a character and
12.
categorizes number and vowels.
Write a program that inputs number of
13.
terms and prints Fibonacci series for it.
Write a function that checks if a number
is a prime number and has an input
14. parameter i.e. num and returns a value if
num is prime otherwise returns a value
of 0.
Write a program to merge the contents of
15.
two text files.
Write a program that uses a function to
16.
calculate the area of a triangle.
Practical No 1
Object:
Write a program that prints a text in four lines, consisting of characters,
integers, and floating point values using printf() statement and escape
sequences.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Use printf() to print a character.
3. Use printf() to print an integer.
4. Use printf() to print a floating point value.
5. Use printf() to print a string.
6. End the program.
Flowchart:
Practical No 2
Object:
Write a program that converts Fahrenheit into Celsius.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables for Fahrenheit and Celsius.
3. Prompt the user to enter the temperature in Fahrenheit.
4. Read the Fahrenheit temperature.
5. Convert the Fahrenheit temperature to Celsius using the
formula. Celsius = 5.0 / 9.0 * (fahrenheit - 32)
6. Print the Celsius temperature.
7. End the program.End the program.
Flowchart:
Practical No 3 a
Object:
Write a program that finds the area of a triangle.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables for base, height, and area.
3. Prompt the user to enter the base of the triangle.
4. Read the base value.
5. Prompt the user to enter the height of the triangle.
6. Read the height value.
7. Calculate the area using the formula: area = 0.5 * base * height.
8. Print the calculated area.
9. End the program.
Flowchart:
Practical No 3 b
Object:
Program to Calculate the Area of a Circle
Source Code:
Output:
Algorithm:
1. Start
2. Declare variables: radius and area
3. Define the value of PI as 3.14159
4. Prompt user for the radius of the circle
5. Calculate the area using the formula area = PI * radius * radius
6. Display the area
7. End
Flowchart:
Practical No 3c
Object:
Program to Calculate the Volume of a Sphere
Source Code:
Output:
Algorithm:
1. Start
2. Declare variables: radius and volume
3. Define the value of PI as 3.14159
4. Prompt user for the radius of the sphere
5. Calculate the volume using the formula volume = (4/3) * PI *
radius^3
6. Display the volume
7. End
Flowchart:
Practical No 4
Object:
Create a program to input and output a statement using printf and scanf.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare a character array statement to store the input.
3. Use printf to prompt the user to enter a statement.
4. Use scanf to read the input statement.
5. Use printf to display the entered statement.
6. End the program.
Flowchart:
Practical No 5
Object:
Write a program that uses getchar() statement to enter the value for a, b,
c variables and uses putchar() statement to display it on the screen.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables for a, b, and c of type char.
3. Prompt the user to enter three characters.
4. Read the characters using getchar().
5. Display the characters using putchar().
6. End the program.
Flowchart:
Practical No 6
Object:
Write a program that checks whether the entered year is a leap year or
not.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare a variable for the year.
3. Prompt the user to enter a year.
4. Check if the year is divisible by 4.
5. If divisible by 4, check if the year is divisible by 100.
6. If divisible by 100, check if the year is divisible by 400.
7. If divisible by 400, print that the year is a leap year.
8. If not divisible by 400, print that the year is not a leap year.
9. If not divisible by 100, print that the year is a leap year.
10. If not divisible by 4, print that the year is not a leap year.
11. End the program.
Flowchart:
Practical No 7
Object:
Write a program to check if a person is eligible to vote or not.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare a variable age of type int.
3. Input age.
4. Check if the age is greater than or equal to 18.
5. If true, they are eligible to vote; otherwise, they are not eligible to
vote.
6. Display the eligibility status.
7. End the program.
Flowchart:
Practical No 8
Object:
Write a program that inputs the cost of any item and if cost is greater
than Rs.50,000, 5% tax is added to it.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables for cost and total_cost of type float.
3. Prompt the user to enter the cost of the item.
4. Read the cost .
5. Check if the cost is greater than Rs.50,000.
6. If true, add 5% tax to the cost.
7. If false, the total cost is the same as the input cost.
8. Print the total cost.
9. End the program.
Flowchart:
Practical No 9
Object:
Write a program that asks income and number of dependents. If number
of dependents is greater than 5 then no income tax is added otherwise
8% tax is applied to income amount.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables for income, tax of type float, and dependents of
type int.
3. Prompt the user to enter their income.
4. Prompt the user to enter the number of dependents.
5. Check if the number of dependents is greater than 5.
6. If true, no tax is applied.
7. If false, calculate the tax as 8% of the income.
8. Print the income tax
9. End the program.
Flowchart:
Practical No 10
Object:
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables num1, num2 of type int and operation of type char.
3. Prompt the user to enter two numbers.
4. Read the numbers using scanf().
5. Prompt the user to enter the desired operation (+, -, *, /).
6. Read the operation using scanf().
7. Use an if-else ladder to perform the operation based on the input:
If +, add the numbers.
If -, subtract the numbers
If *, multiply the numbers.
If /, divide the numbers.
8. Display the result.
9. End the program.
Flowchart:
Practical No 11
Object:
Write a program to print days of the week using switch-case statement.
Source Code:
Output:
A
Algorithm:
1. Start the program.
2. Declare a variable day of type int.
3. Prompt the user to enter a day number (1-7).
4. Read the day number .
5. Use a switch-case statement to determine the day of the week:
Case 1: Print "Monday".
Case 2: Print "Tuesday".
Case 3: Print "Wednesday".
Case 4: Print "Thursday".
Case 5: Print "Friday".
Case 6: Print "Saturday".
Case 7: Print "Sunday".
Default: Print "Invalid day number".
6. End the program.
Flowchart:
Practical No 12
Object:
Write a program that inputs a character and categorizes it as a number
or vowel.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare a variable ch of type char.
3. Prompt the user to enter a character.
4. Read the character using scanf().
5. Check if the character is between '0' and '9'. If true, categorize it as
a number.
6. If false, check if the character is a vowel (both uppercase and
lowercase).
7. If true, categorize it as a vowel.
8. If false, categorize it as neither a number nor a vowel.
9. Use the printf() function to display the category.
10. End the program.
Flowchart:
Practical No 13`
Object:
Write a program that inputs the number of terms and prints the Fibonacci
series for it.
Source Code:
Output:
Algorithm:
1. Start the program.
2. Declare variables n, i, t1, and t2 of type int, and nextTerm of type int.
3. Initialize t1 to 0 and t2 to 1.
4. Prompt the user to enter the number of terms.
5. Read the number of terms using scanf().
6. Print the first two terms (t1 and t2).
7. Use a loop to calculate the next terms in the Fibonacci series:
8. For i from 3 to n:
Calculate the next term as the sum of t1 and t2.
Print the next term.
Update t1 and t2 to the next term.
9. End the program.
Flowchart:
Practical No 14
Object:
Write a function that checks if a number is a prime number and has an
input parameter i.e. num and returns a value if num is prime otherwise
returns a value of 0.
Source Code:
Output 1:
Output 2:
Algorithm:
• Start the program.
Object:
Write a program to merge the contents of two text files.
Source Code:
Output:
Algorithm:
Start the program.
Define a function mergeFiles that takes three file names as input:
file1, file2, and outputFile.
Open file1 in read mode, file2 in read mode, and outputFile in write
mode.
Check if any of the files failed to open. If so, print an error
message and exit.
Copy the contents of file1 to outputFile.
Copy the contents of file2 to outputFile.
Print a success message.
Close all three files.
In the main function, call mergeFiles with appropriate file names.
End the program.
Flowchart:
Practical No 16
Object:
Write a program that uses a function to calculate the area of a triangle.
Source Code:
Output:
Algorithm:
Start the program.
Define a function calculateArea that takes base and height as input
and returns the area of the triangle.
In the main function, declare variables base, height, and area of
type float.
Prompt the user to enter the base of the triangle.
Read the base using scanf().
Prompt the user to enter the height of the triangle.
Read the height using scanf().
Call the calculateArea function with base and height as arguments.
Store the returned area in the variable area.
Print the area using printf().
End the program.
Flowchart: