0% found this document useful (0 votes)
5 views14 pages

Practical File Hridhay

The document outlines multiple programming tasks including an arithmetic calculator, interest calculations, number swapping methods, and leap year checks. Each program includes an algorithm, flowchart, and source code. The tasks demonstrate fundamental programming concepts and operations in a structured format.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views14 pages

Practical File Hridhay

The document outlines multiple programming tasks including an arithmetic calculator, interest calculations, number swapping methods, and leap year checks. Each program includes an algorithm, flowchart, and source code. The tasks demonstrate fundamental programming concepts and operations in a structured format.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

HRIDHAY CHAUDHARY

Program 1
Write a Program to design Arithmetic Calculator.

Algorithm:
1. Start
2. Declare variables:
a. operator (character)
b. num1, num2, result (floating-point numbers)
3. Get first number from user
4. Get operator (+, -, *, /) from user
5. Get second number from user 6. If operator is:
a. '+' : add num1 and num2
b. '-' : subtract num2 from num1
c. '*' : multiply num1 and num2
d. '/' : If num2 is not zero, divide num1 by num2 Else, show error message and end.
7. Store calculation in result
8. Display result
9. End Flowchart:

Source Code:
HRIDHAY CHAUDHARY

Output:

Program 2
Write a program to find Simple and Compound Interest.
HRIDHAY CHAUDHARY

Algorithm:

1. Start
2. Declare variables:
a. principal (float)
b. rate (float)
c. time (float)
d. simple_interest (float)
e. compound_interest (float) 3. Input:
a. Read principal from user
b. Read rate from user
c. Read time from user 4. Calculate Simple Interest:
a. Simple_interest = (principal × rate × time) ÷ 100 5.
Calculate Compound Interest:
a. compound_interest = principal × pow(1 + rate/100, time) – principal 6.
Output:
a. Display simple_interest
b. Display compound_interest 7. End

Flowchart:
HRIDHAY CHAUDHARY
HRIDHAY CHAUDHARY

Source Code:

Output:

Program 3 (a)
HRIDHAY CHAUDHARY

Write a program to swap two numbers using temporary variable.

Algorithm:

1. Start
2. Declare variables:
a. a (first number)
b. b (second number)
c. temp (temporary variable) 3. Assign values:
a. Set a = 5
b. Set b = 10
4. Display initial values: Printf( "Before swapping: a = %d, b=%d\n”, a,b) 5.
Swap numbers:
a. Store a in temp (temp = a)
b. Assign b to a (a = b)
c. Assign temp to b (b = temp)
6. Display final values: Printf( "After swapping: a = %d, b=%d\n”, a,b)
7. End

Flowchart:
HRIDHAY CHAUDHARY

Source Code:

Output:

Program 3 (b)
Write a program to swap two numbers without using temporary variable.

Algorithm:

1. Start
HRIDHAY CHAUDHARY

2. Take two numbers, let them be A = 5 and B = 10


3. Show "Before swapping: A = 5, B = 10"
4. Add A and B, store result in A (A becomes 15)
5. Subtract B from new A, store result in B (B becomes 5)
6. Subtract new B from A, store result in A (A becomes 10)
7. Show "After swapping: A = 10, B = 5"
8. End

Flowchart:
HRIDHAY CHAUDHARY

Source Code:

Output:

Program 4(a)
Write a program to check whether a year is a leap year or not using conditional operator

Algorithm:
1. Start
HRIDHAY CHAUDHARY

2. Input the year from the user


3. Check if the year satisfies leap year conditions:
4. A year is a leap year if:
a. It is divisible by 4 AND not divisible by 100, OR
b. It is divisible by 400
5. If condition is true, display "leap year"
6. If condition is false, display "not a leap year"
7. End

Flowchart:
HRIDHAY CHAUDHARY

Source Code:

Output:

Program 4(b)
Write a program to find roots of a quadratic equation using conditional operator

Algorithm:
1. Start
HRIDHAY CHAUDHARY

2. Input coefficients a, b, and c 3. Calculate discriminant = b² - 4ac 4.


If discriminant > 0:
a. root1 = (-b + √discriminant)/(2a)
b. root2 = (-b - √discriminant)/(2a)
c. Display "Real and Different roots" 5. Else if discriminant = 0:
a. root1 = root2 = -b/(2a)
b. Display "Real and Equal roots" 6. Else (discriminant <
0):
a. real part = -b/(2a)
b. imaginary part = √(-discriminant)/(2a)
c. Display "Imaginary roots"
7. Output the roots
8. End
HRIDHAY CHAUDHARY

Flowchart:
HRIDHAY CHAUDHARY

Source Code:

Output:

You might also like