Practical File Hridhay
Practical File Hridhay
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
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
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
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
Flowchart:
HRIDHAY CHAUDHARY
Source Code:
Output: