QP : May-2021 – PPS [MID SEM]

Solution :

Ques:2)  A flowchart is a visual representation of a process or algorithm, using symbols and arrows to show the sequence of steps and decision points. It helps to visualize the flow of information and actions in a clear and structured manner.

An algorithm is a step-by-step set of instructions for solving a problem. An algorithm is a set of instructions for solving a problem or achieving a goal. It provides a clear and organized way to approach and tackle tasks efficiently.

Flowchart Symbol Name Description 
Process symbol Also known as an “Action Symbol,” this shape represents a process, action, or function. It’s the most widely used symbol in flowcharting. 
 Start/End symbol Also known as the “Terminator Symbol,” this symbol represents the start points, end points, and potential outcomes of a path. Often contains “Start” or “End” within the shape. 
 Input/Output symbol Also referred to as the “Data Symbol,” this shape represents data that is available for input or output as well as representing resources used or generated. While the paper tape symbol also represents input/output, it is outdated and no longer in common use for flowchart diagramming. 
 Decision symbol Indicates a question to be answered — usually yes/no or true/false. The flowchart path may then split off into different branches depending on the answer or consequences thereafter. 
Arrow Shows relationships between different shapes. 

Ques 2 A)

Flowchart to calculate the factorial of a number

flowchart for factorial of a number

Algorithm of factorial of a number

Step 1: Start
Step 2: Read a number n
Step 2: Initialize variables:
i = 1fact = 1
Step 3:  if i <= n go to step 4 otherwise go to step 7
Step 4: Calculate
fact = fact * i
Step 5: Increment the i by 1 (i=i+1) and go to step 3
Step 6: Print fact
Step 7: Stop

Ques 2 B)

A loop is a programming construct that allows a section of code to be executed repeatedly based on a certain condition. In C language, there are four types of loops: for, while, do-while, and goto. 

For Loop: 

The for loop is used to execute a block of code repeatedly for a fixed number of times.  

The syntax of a for loop is as follows: 

The initialization step is executed only once at the beginning of the loop. The condition is checked before each iteration of the loop, and if it is true, the code inside the loop is executed. After each iteration, the increment/decrement step is executed. The loop stops when the condition becomes false. 

Example: 

While Loop: 

The while loop is used to execute a block of code repeatedly as long as a certain condition is true.  

The syntax of a while loop is as follows: 

The condition is checked at the beginning of each iteration of the loop, and if it is true, the code inside the loop is executed. The loop continues until the condition becomes false. 

Example: 

Do-While Loop: 

The do-while loop is similar to the while loop, but it guarantees that the code inside the loop is executed at least once.  

The syntax of a do-while loop is as follows: 

The code inside the loop is executed first, and then the condition is checked. If the condition is true, the loop continues, and if it is false, the loop stops. 

Example: 

Ques 2 B)

A 2D array is a collection of elements of the same data type that are organized in a matrix format with rows and columns. It can be thought of as a table with rows and columns, where each cell holds a value.The syntax for declaring a 2D array is as follows: 

datatype arrayname[rows][columns]; 

For example, to declare a 2D array of integers with 3 rows and 4 columns, the syntax would be: 

int arr[3][4]; 

To access an element in the 2D array, we use two indices inside square brackets, one for the row and one for the column. 

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!
Scroll to Top