CP LAB Algorithm and Flowchart Upto Week 6
CP LAB Algorithm and Flowchart Upto Week 6
Algorithm:
Step 1: Start.
Step 3: Stop.
Flowchart:
(pgm1b) //Write a C program to print a block F using hash (#), where the F has a
heightof six characters and width of five and four characters.
Algorithm:
Step 1: Start.
Step 3: Stop.
Flowchart:
Algorithm:
Step 1: Start.
Flowchart:
Algorithm:
Step 1: Start.
Step 9: Stop.
Flowchart:
(pgm1e) //C-Program to compute the perimeter and area of a rectangle with a height
of 7 inches and width of 5 inches.
Algorithm:
Step 1: Start.
Step 8: Stop.
Flowchart:
Week 2: (Exercise 2)
(pgm2a) //C Program to find Sum and Average of 3 Numbers
Algorithm:
Step 1: Start.
Step 8: Stop.
Flowchart:
1.
Algorithm:
Step 1: Start.
Step 7: Stop.
Flowchart:
Algorithm:
Step 1: Start.
Step 6: Stop.
Flowchart:
Week 3: (Exercise 3)
(pgm3a) //C program to find the square root of a number using sqrt function.
Algorithm:
Step 1: Start.
Step 6: Stop.
Flowchart:
Algorithm:
Step 1: Start.
Step 2: Declare variables for principal (p), rate (r), time (t), and compound interest
(ci).
Step 3: Read the values principal (p), rate (r), time (t).
Step 4: Calculate the compound interest using the provided formula.
𝑟
Compound Interest=P(1+ )𝑡 −P
100
(pgm3c) //C Program to Calculate Area of Any Triangle using Heron's Formula
Algorithm:
Step 1: Start.
Step 2: Declare variables, lengths of three sides of the triangle a,b,c and semi-
perimeter, area. (a, b, c, s, area)
Algorithm:
Step 1: Start.
Step 7: Stop.
Flowchart:
Unit 2
Week 4: (Exercise 4)
i)a+b*c+(d*e)+f*g
ii)a/b*c-b+a*d/3
iii)(a++)+b-(--a)
iv)j=(i++)+(++i)
Algorithm:
Step 1: Start.
Step 2: Initialize variables a, b, c, d, e, f, g, i as floats.
Step 3: Display "Enter values:"
Read a, b, c, d, e, f, g, i from the user.
Step 4: Calculate a+b*c+(d*e)+f*g and
Display "a+b*c+(d*e)+f*g".
Step 5: Calculate a/b*c-b+a*d/3 and
Display "a/b*c-b+a*d/3.
Step 6: Calculate (a++)+b-(--a) and
Display (a++)+b-(--a).
Step 7: Calculate j = (i++)+(++i).
Display j.
Step 8: Stop.
Flowchart:
Algorithm:
Step 1: Start.
Step 6: Calculate max = (n1 > n2) ? (n1 > n3 ? n1 : n3) : (n2 > n3 ? n2 : n3).
Step 8: Stop.
Flowchart:
(pgm4c) Take marks of 5 subjects in integers, and find the total, average in float
Algorithm:
Step 1: Start.
Flowchart:
Week 5: (Exercise 5)
(pgm5a) Write a C program to find max and min of four numbers using if else.
Algorithm:
Step 1: Start.
Step 2: Initialize variables a, b, c, d as integers.
Step 3: Display "Enter four numbers:"
Read a, b, c, d from the user.
Step 4: // Find Maximum
if (a > b and a > c and a > d)
Display "a is the maximum value."
else if (b > a and b > c and b > d)
Display "b is the maximum value."
else if (c > a and c > b and c > d)
Display "c is the maximum value."
else
Display "d is the maximum value."
Step 5: // Find Minimum
if (a < b and a < c and a < d)
Display "a is the minimum value."
else if (b < a and b < c and b < d)
Display "b is the minimum value."
else if (c < a and c < b and c < d)
Display "c is the minimum value."
else
Display "d is the minimum value."
Step 6: Stop.
Flowchart:
Algorithm:
Step 1: Start.
else
Step 6: Stop.
Flowchart:
Algorithm:
Step 1: Start.
dis = b * b - 4 * a * c;
if (dis > 0)
else if (dis == 0)
else
rp = -b / (2 * a);
ip = sqrt(-dis) / (2 * a);
Display "Root 1 =", rp, "+", ip, "i and Root 2 =", rp, "-", ip, "i."
Step 6: Stop.
Flowchart:
Algorithm:
Step 1: Start.
Calculate res = a / b;
Display "Division of", a, "/", b, "is:", res.
break;
default:
Display "Invalid Choice".
break;
Step 6: Stop.
Flowchart:
(pgm5e) Write a C program to find the given year is a leap year or not.
Algorithm:
Step 1: Start.
else
Step 5: Stop.
Flowchart:
Week 6: (Exercise 6)
Algorithm:
Step 1: Start
Step 2: Initialize variables: n, i, and fact to store the input number, loop variable, and
factorial respectively.
Step 5: Loop:
Repeat the following steps until i becomes greater than n.
Multiply fact by i.
Increment the value of i by 1.
End Loop
Step 7: Stop.
Flowchart:
Algorithm:
Step 1: Start
Step 6: Stop.
Flowchart:
Algorithm:
Step 1: Start
Step 2: Declare constants PI and MAX with values 3.1416 and 180, respectively.
Step 6: Stop.
Flowchart:
// Sin series
Algorithm:
Step 1: Start
Step 2: Declare constants PI and MAX with values 3.1416 and 180, respectively.
Step 6: Stop.
Flowchart:
Algorithm:
Step 1: Start
Step 8: Stop.
Flowchart:
Algorithm:
Step 1: Start
Step 5: Stop.
Flowchart: