0% found this document useful (0 votes)
7 views

PC File

The document outlines the B.Tech Programming in C course at Vivekananda Institute of Professional Studies, detailing its accreditation and affiliation. It includes the vision and mission of the institute, a series of programming exercises, algorithms, and learning outcomes related to factorial calculation and geometric progression. Additionally, it provides a structured approach to programming concepts through theoretical explanations, source code, and flowcharts.

Uploaded by

rairishvesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

PC File

The document outlines the B.Tech Programming in C course at Vivekananda Institute of Professional Studies, detailing its accreditation and affiliation. It includes the vision and mission of the institute, a series of programming exercises, algorithms, and learning outcomes related to factorial calculation and geometric progression. Additionally, it provides a structured approach to programming concepts through theoretical explanations, source code, and flowcharts.

Uploaded by

rairishvesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS

Grade A++ Accredited Institution by NAAC


NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution

SCHOOL OF ENGINEERING & TECHNOLOGY

B.Tech Programme:

Course Title: Programming in C

Course Code: ES-102

Submitted to: Submitted By:


Dr. Parneeta Chaudhary Name:
Enrollment No:
VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

VISION OF INSTITUTE

To be an educational institute that empowers the field of engineering to build a


sustainable future by providing quality education with innovative practices that
supports people, planet and profit.

MISSION OF INSTITUTE

To groom the future engineers by providing value-based education and awakening


students' curiosity, nurturing creativity and building
capabilities to enable them to make significant contributions to the world.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

INDEX

S.No EXP. Date Marks Remark Updated Faculty


Marks Signature
Laborat Class Viva
ory Participation (5
Assess (5 Marks) Marks)
ment
(15
Marks)
1 Write a program 4.03.25
to find the
divisor or
factorial of a
given number.
2 Write a program 11.03.25
to find sum of
GP series using
formula, for
loop, and
function.
3 Write a 18.03.25
Recursive
Program for
Tower Of Hanoi
Problem.
4 A recursive 25.03.25
program to print
the first m
Fibonacci
number.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

S.No EXP. Date Marks Remark Updated Faculty


Marks Signature
Laborat Class Viva
ory Participation (5
Assess (5 Marks) Marks)
ment
(15
Marks)
5 Menu driven 26.03.25
program for
matrices to do
the following
operation
depending on
whether the
operations
required one or
two matrices.
a) Addition of
two matrices.
b) subtraction of
two matrices
c) printing upper
and lower
triangular
matrices.
d) transpose of
matrix
e) product of two
matrices

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

S.No EXP. Date Marks Remark Updated Faculty


Marks Signature
Laborat Class Viva
ory Participation (5
Assess (5 Marks) Marks)
ment
(15
Marks)
5 WAP to perform 26.03.25
the following
operations on
Strings
“without” using
String Function
A. To find the
length of a string
B. To
concatenate two
strings
C. To find
Reverse of a
string
D. To copy one
string to another
string

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

INDEX (BEYOND CURRICULUM)

S.No EXP. Date Marks Remark Updated Faculty


Marks Signature
Laboratory Class Viva
Assessment Participation (5
(15 Marks) (5 Marks) Marks)
1
2
3

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

INDEX (PRACTICE QUESTIONS)

S.No EXP. Date Marks Remark Updated Faculty


Marks Signature
Laboratory Class Viva
Assessment Participation (5
(15 Marks) (5 Marks) Marks)
1
2
3

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

EXERCISE - 1
Theory
Step-by-step explanation of how a typical C program
calculates the factorial of a given number:

● Include Standard Libraries: The program starts by


including the standard input-output library (stdio.h)
which allows the program to use functions like
"printf()" and "scanf()".
● Main Function: The "main()" function is the entry point
of the program where execution begins.
● Declare Variables: The program declares an integer
variable, typically n, to store the number for which
the factorial is to be calculated. Another variable,
often called 'result', is initialized to 1 to store the
factorial result.
● Input the Number: The program prompts the user to enter
a number and reads the input using the "scanf()"
function. This input is stored in the variable 'n'.
● Factorial Calculation (Using a Loop):
○ A loop (such as a "for" loop or "while" loop) runs
from 1 to the given number 'n'.
○ In each iteration of the loop, the current value
of the loop counter is multiplied by 'result', and
the result is stored back in 'result'.
○ For example, if n is 5, the loop iterates as
follows:
➢ result = result * 1 (result is now 1)
➢ result = result * 2 (result is now 2)
➢ result = result * 3 (result is now 6)
➢ result = result * 4 (result is now 24)
➢ result = result * 5 (result is now 120)

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

● Output the Result: After the loop completes, the


program prints the value of 'result', which now holds
the factorial of the input number 'n'.
● Return Statement: The "main()" function returns 0 to
indicate that the program executed successfully.

Algorithm
Step-1 : Start.
Step-2 : Read n.
Step-3 : Initialize counter variable i to 1 and fact to 1.
Step-4 : if i <= n go to step 5 otherwise go to step 7.
Step-5 : calculate fact = fact * i.
Step-6 : increment counter variable i and go to step 4.
Step-7 : Write fact.
Step-8 : Stop.
Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Output

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes

1.Understanding how to calculate the factorial of a number


using a loop in C.
2.Learning the use of for loops for iterative multiplication
and updating variables.
3.Practicing input handling with scanf() and output display
with printf().

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Exercise - 2

Theory

Geometric Progression (GP) is a type of sequence where each


succeeding term is produced by multiplying each preceding
term by a fixed number, which is called a common ratio. This
progression is also known as a geometric sequence of numbers
that follow a pattern. Also, learn arithmetic progression
here. The common ratio multiplied here to each term to get
the next term is a non-zero number. An example of a Geometric
sequence is 2, 4, 8, 16, 32, 64, …, where the common ratio is
2.
What is Geometric Sequence?: A geometric progression or a
geometric sequence is the sequence, in which each term is
varied by another by a common ratio. The next term of the
sequence is produced when we multiply a constant (which is
non-zero) to the preceding term. It is represented by:
a, ar, ar2, ar3, ar4, and so on.
Where a is the first term and r is the common ratio.
Note: It is to be noted that when we divide any succeeding
term from its preceding term, then we get the value equal to
the common ratio.
In this program, we will find the sum of a geometric series
without using both formulas and functions. Firstly, the first
term, the total number of terms, and the common ratio are
declared. Then, we declare two variables; one for sum and the
other for the number. In each iteration we will keep on
updating both the elements and at the end will print the
result.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Algorithm
1. Start
2. Declare the variables.
3. Initialize the first term, the total number of terms, and
the common ratio.
4. Use a for loop that will calculate the sum.
5. Declare two variables for sum and element.
6. Update both the elements in each iteration
7. At the end display the calculated sum.
8. Stop

Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Output

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes
1. Understanding how to calculate the sum of GP series
using formula and for loop in C.
2. Understanding using different libraries such as math.h
and performing arithmetic operations.
Problem – 2 : Sum of GP Series using
For Loop
Theory
In this program, we will find the sum of a geometric series
using a for loop.
Firstly, the first term, the total number of terms, and the
common ratio are declared. Then, we calculate the total sum
of the geometric series using the formula and print it using
the for loop.
ALGORITHM:
1. Start
2. Declare the variables.
3. Initialize the first term, the total number
of terms, and the common ratio. 4. Use a for
loop that will calculate the sum.
5. Declare the formula for sum and last term before the
loop.
6. Calculate the sum till the last element in the for
loop.
7. Display the sum.
8. Stop.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Flowchart:

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code:

Output

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes
1. Understanding how to calculate sum of GP series using
just a for loop and through basic arithmetic
operations.

Problem – 3 : Sum Of GP Series using


both Formula and Function
Theory
In this method, we will find the sum of a geometric series
using both formulas and functions.
Firstly, the first term, the total number of terms, and the
common ratio are declared. Then, a function is called to
calculate the total sum of the geometric series.

Algorithm
1. Start
2. Declare the variables.
3. Initialize the first term, the total number of terms, and
the common ratio.
4. Call the function that will calculate the sum.
5. Declare the formula for sum and last term in the function.
6. Calculate the sum till the last element.
7. Display the sum.
8. Stop.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Output:

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes
1. Understanding how to calculate sum of GP series using
a function instead of performing it in main.
2. Understanding functions, how to call a function and
function parameters.

Exercise – 3 : Write a Recursive


Program for Tower Of Hanoi Problem
Theory
Tower of Hanoi is a mathematical puzzle where we have
three rods (A, B, and C) and N disks. Initially, all the
disks are stacked in decreasing value of diameter i.e., the
smallest disk is placed on the top and they are on rod A.
The objective of the puzzle is to move the entire stack to
another rod (here considered C), obeying the following simple
rules:
• Only one disk can be moved at a time.
• Each move consists of taking the upper disk from one of
the stacks and placing it on top of another stack i.e. a
disk can only be moved if it is the uppermost disk on a
stack.
• No disk may be placed on top of a smaller disk.

Algorithm
1. Step 1 − Move n-1 disks from source to aux
2. Step 2 − Move nth disk from source to dest
3. Step 3 − Move n-1 disks from aux to dest
4. A recursive algorithm for Tower of Hanoi can be
driven as follows −
5. START
6. Procedure Hanoi(disk, source, dest, aux)
7. IF disk == 1, THEN
8. move disk from source to dest

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

9. ELSE
10. Hanoi(disk - 1, source, aux, dest)
11. move disk from source to dest
Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Output

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes
1. Understanding Recursion, and how to solve the tower
of Hanoi problem using Recursion.
2. Understanding Base Cases in Recursion.
3. Learning how to perform Recursion through the tower
of Hanoi problem.
Exercise – 3 : a recursive program to
print the first m Fibonacci number.
Theory
The Fibonacci sequence is a sequence where the next term is
the sum of the previous two terms. The first two terms of
the Fibonacci sequence are 0 followed by 1. The Fibonacci
sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21
We can use recursion to solve this problem because any
Fibonacci number n depends on previous two Fibonacci
numbers. Therefore, this approach repeatedly breaks down
the problem until it reaches the base cases.
In mathematical terms, the number at the mth position can
be represented by:
Fn = Fn-1 + Fn-2
where, F0 = 0 and F1 = 1.
For example, Fibonacci series 10 terms are: 0, 1, 1, 2, 3,
5, 8, 13, 21, 34.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Algorithm
1. START.
2. Declare variable n
3. Initialize variables:
4. Read n.
5. The recursive function is as follows:
6. If n < = 1:
7. Return n
8. Else:
9. Return integer nthFibonacci(n-1) + nthFibonacci(n-2)
10. Call the function nthFibonacci(n) in main and output
the result
11. Step 6: STOP.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Output

Learning Outcomes
1. Understanding how to calculate a Fibonacci number
mathematically and then calculate it using C.
2. Understanding how to calculate a Fibonacci number
using Recursion.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Exercise - 5 : Menu driven


program for matrices to do the
following operation depending on
whether the operations required
one or two matrices.
a) Addition of two matrices.
b) subtraction of two matrices
c) printing upper and lower
triangular matrices.
d) transpose of matrix
e) product of two matrices
Theory
Matrix Operations are the operations that are
operated on the matrix. Matrix Operation includes
operations such as Addition of Matrix, Subtraction
of Matrix, Multiplication of Matrix, etc, and
others. These operations are very useful for
solving various problems of matrices and help us
to find the transpose, inverse, rank, and others
of the matrix. These operations help us to combine
two or matrices.
Algorithm:
1. Start
2. Input Matrix 1:

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

• Ask the user for the number of rows (a) and columns
(b).
• Take input for elements and store them in
matrix1[a][b].
3. Input Matrix 2:
• Ask the user for the number of rows (c) and columns
(d).
• Take input for elements and store them in
matrix2[c][d].
4. Display Menu:
• Show options for matrix operations:
• Addition
• Subtraction
• Upper & Lower Triangular Matrix
• Transpose
• Multiplication
• Exit
5. Perform Addition (if chosen):
• Check if matrices have the same dimensions (a == c
and b == d).
• Subtract corresponding elements and display the
result.
6. Print Upper & Lower Triangular Matrix (if chosen):
• Display the upper triangular matrix (set elements
below the diagonal to 0).
• Display the lower triangular matrix (set elements
above the diagonal to 0).
7. Transpose Matrix (if chosen):
• Swap rows and columns (matrix1[j][i]).
• Display the transposed matrix
8. Multiply Matrices (if chosen):
• Check if multiplication is possible (b == c).

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

• Use nested loops to calculate the product and display


the result.
9. Exit the Program (if chosen):

• If the user selects Exit (6), terminate the loop and


end the program.
10. End.

Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Output

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes
1. Understanding Matrix Operations learn how to perform
fundamental matrix operations like addition,
subtraction, multiplication, transpose, and
identifying triangular matrices.
2. Dynamic Input Handling understand how to take user
input for variable-sized matrices and store them in a
2D array.
3. Conditional Statements & Error Handling learn to
validate operations by checking matrix dimensions
before performing addition, subtraction, or
multiplication.
4. Problem-Solving Skills breaking down complex matrix
operations into step-by-step algorithms.
5. Memory and Performance Considerations understanding
static array allocation in C.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

EXERCISE 8: WAP to perform the


following operations on Strings
“without” using String Function
a. To find the length of a string
b. To concatenate two strings
c. To find Reverse of a string
d. To copy one string to another
string
Algorithm
1. Start
2. Initialize variables:

• s1[20]: Array to store the original string.


• s2[20]: Array to store the copied string.
• s3[20]: Array to store the reversed string.
• i: Variable for indexing during the operations.
• l: Variable to store the length of the string.
• j: Variable for indexing during the reversal
operation.

3. Input the string:

• Display a prompt to the user: "Enter your


name:".
• Read the string input using scanf with a size
limit of 19 characters to avoid overflow. This
stores the input in s1.

4. Copy the string s1 to s2:

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

• Initialize i to 0.
• Loop until the end of the string s1 (when s1[i]
== '\0'):
o Copy each character of s1[i] to s2[i].
o Increment i.
• After the loop, set s2[i] = '\0' to null-
terminate the copied string.
• Print the copied string s2.

5. Calculate the length of the string:

• Initialize l to 0.
• Loop through s1 and increment l until the null
character \0 is encountered (end of the string).
• Print the calculated length l.

6. Reverse the string:

• Initialize i = l - 1 (starting from the last


character of the string) and j = 0 (starting at
the beginning of s3).
• Loop until i >= 0:
o Copy each character from s1[i] to s3[j].
o Decrement i and increment j.
• After the loop, set s3[j] = '\0' to null-
terminate the reversed string.
• Print the reversed string s3.

7. End.

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Flowchart

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Source Code

Output

Abhishek Bhardwaj 08817749524


VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES - TECHNICAL CAMPUS
Grade A++ Accredited Institution by NAAC
NBA Accredited for MCA Programme; Recognized under Section 2(f) by UGC;
Affiliated to GGSIP University, Delhi; Recognized by Bar Council of India and AICTE
An ISO 9001:2015 Certified Institution
SCHOOL OF ENGINEERING & TECHNOLOGY

Learning Outcomes
1. Understanding how to find the length of a
string without using strlen().
2. Understanding how to concatenate two
strings in C without using strcat()
function.
3. Understanding how to Reverse a string in C
without using strrev() function.
4. Understanding how to copy one string to
another string in C without using strcpy()
function.

Abhishek Bhardwaj 08817749524

You might also like