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

INT 1 CPDS Set 1 - Answers

This document outlines an internal test for the C programming and Data Structures course at CMS College of Engineering and Technology, detailing the test structure, topics covered, and sample questions. It includes definitions and explanations of key programming concepts such as recursive functions, ternary operators, unions, looping mechanisms, and control statements, along with examples and C code snippets. The test aims to assess students' understanding of linear and non-linear data structures and their ability to execute relevant operations.

Uploaded by

Athulya
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)
9 views14 pages

INT 1 CPDS Set 1 - Answers

This document outlines an internal test for the C programming and Data Structures course at CMS College of Engineering and Technology, detailing the test structure, topics covered, and sample questions. It includes definitions and explanations of key programming concepts such as recursive functions, ternary operators, unions, looping mechanisms, and control statements, along with examples and C code snippets. The test aims to assess students' understanding of linear and non-linear data structures and their ability to execute relevant operations.

Uploaded by

Athulya
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

CMS COLLEGE OF ENGINEERING AND TECHNOLOGY

(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)


(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

DEPARTMENT OF ELECRONICS & COMMUNICATION


Internal Test –I

Sub Code:CS3353 SET I Date: 15.09.2025


Sub Name: C programming & Data Structures Maximum Marks:60
Department: Electronics & Communication Duration:1.30hr
Year: II Semester: III
CO1 Describe the differences between linear and non-linear data structures.

CO2 Execute operations on both linear and non-linear data structures.

Part A (Answer all Questions) 5x 2 =10 Marks

1) What is a recursive function?

A recursive function is a function that calls itself in order to solve a problem.


Key Characteristics:
1. Base Case: This is the condition under which the function stops calling itself (to prevent infinite recursion).
2. Recursive Case: This is where the function calls itself with a simpler or smaller version of the original
problem.

2) When the ternary operator is used?

In C, the ternary operator is used as a shorthand for an if-else statement. It's mainly used to assign a value
based on a condition in a compact, single-line format.
Syntax:
condition ? expression_if_true : expression_if_false;

3) State the usage of union?

A union is a special data type that allows storing different data types in the same memory location. It is
similar to a struct, but with one key difference: all members of a union share the same memory space.

Syntax:

union Data {
int i;
float f;
char str[20];
};

4) What is the output of the given program?


#include “stdio.h”
Int main()
{
Int x,y=5,z=5;
X=y=z;
Printf(“%d” , x);
getchar();
return 0;
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

Step-by-step explanation:

1. Variable declaration and initialization


o y=5
o z=5
o x is declared but not initialized yet.
2. Assignment x = y = z;
o In C, assignment (=) is right-associative, meaning it evaluates from right to left.
o First: y = z; → y becomes 5.
o Then: x = y; → x becomes 5.
3. So final values:
o x=5
o y=5
o z=5
4. Output: 5

5) What is enumerated Datatype?

An enumerated data type (enum) in C (and many other languages) is a user-defined data type that consists of a
set of named integer constants.
It is used when you want to represent a group of related values with meaningful names instead of just
numbers, which improves readability and maintainability of code.

Syntax:

enum enum_name { value1, value2, value3, ... };

Part B (Answer all Questions) 3x 12 =36 Marks

6 a) What is the use of looping? Explain about entry and exit controlled loop with an example?

Looping in C programming is used to repeatedly execute a block of code until a specified condition is met. This
mechanism is crucial for handling repetitive tasks efficiently, avoiding code redundancy, and enhancing program
flexibility.

Primary Uses of Loops in C:

 Code Repetition:
Loops allow a block of code to be executed multiple times without having to write the same code
repeatedly. This saves effort and makes the code more concise and maintainable.
 Iterating through Data Structures:
Loops are fundamental for processing elements within data structures like arrays, strings, and linked
lists. For example, a for loop can easily access each element of an array.
 Performing Calculations Repeatedly:
Tasks requiring repeated calculations, such as summing a series of numbers, finding factorials, or
generating patterns, are efficiently handled using loops.
 Input Validation:
Loops, especially do-while loops, are often used to ensure user input meets specific criteria by repeatedly
prompting for input until valid data is provided.
 Controlling Program Flow:
Loops enable dynamic control over program execution based on runtime conditions. This flexibility allows
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

programs to adapt to varying amounts of data or changing requirements.

Types of Loops in C:

 for loop: Used when the number of iterations is known in advance.


 while loop: Used when the number of iterations is not fixed and depends on a condition being true. The
condition is checked before each iteration.
 do-while loop: Similar to a while loop, but guarantees at least one execution of the loop body because the
condition is checked after the first iteration.

Entry controlled loop:

In an entry-controlled loop, the condition to enter the loop is evaluated before the loop body is executed. This
means that the loop is only entered if the condition evaluates to true initially. If the condition is false from the
outset, the loop is bypassed entirely. The condition is evaluated at the beginning of each iteration, and if it
becomes false at any point, the loop terminates.

Exit controlled loop:

An exit-controlled loop evaluates its condition after executing the loop body. This means that the loop body is
executed at least once, regardless of the condition. After each iteration, the condition is evaluated, and if it
becomes false, the loop terminates.

While Loop Do While Loop


while(condition) {statement(s)} do {statement(s)} while(condition);
Condition is checked before Statement(s) are executed at least once
statement(s) are executed before condition is checked
If condition is false, statement(s) are Even if condition is false initially,
not executed at all statement(s) are executed at least once
Used when you want to execute Used when you want to execute
statement(s) only if condition is true statement(s) first and then check condition
while(i<5) {[Link](i); i++} do {[Link](i); i++} while(i<5);

6b) Distinguish between iterative and recursive function? Write a factorial of 5 numbers using
recursive and iterative function in c?

Iterative functions employ loops (e.g., for, while) to repeatedly execute a block of code until a specified
condition is no longer met. They maintain state through variables that are updated within the loop.
Recursive functions solve a problem by calling themselves with smaller inputs until a base case is
reached. The base case provides a direct solution, and the results from the smaller problems are combined to
solve the original problem.

Key Differences:

 Control Flow:
Iteration uses explicit loops, while recursion uses function calls to repeat operations.
 Termination:
Iteration terminates when the loop condition becomes false. Recursion terminates when the base case is
reached.
 Memory Usage:
Recursion generally uses more memory due to the overhead of maintaining the call stack for each
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

function call. Iteration typically uses less memory.


 Code Structure:
Recursive solutions can sometimes be more concise and elegantly reflect mathematical definitions, while
iterative solutions might be more explicit in their step-by-step process.

Factorial of 5 in C (Iterative and Recursive)

#include <stdio.h>

// Iterative function to calculate factorial


long long factorial_iterative(int n) {
long long result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}

// Recursive function to calculate factorial


long long factorial_recursive(int n) {
if (n == 0 || n == 1) { // Base case
return 1;
} else {
return n * factorial_recursive(n - 1); // Recursive step
}
}

int main() {
int num = 5;

// Calculate factorial using iterative function


printf("Factorial of %d (iterative): %lld\n", num, factorial_iterative(num));

// Calculate factorial using recursive function


printf("Factorial of %d (recursive): %lld\n", num, factorial_recursive(num));

return 0;
}

7a) What are different types of files available? Write a c program to copy the content of one file to another.

Different Types of Files


In the context of computer systems and programming, files can be broadly categorized based on their content and how they are interpreted:

 Text Files:

These files store data as a sequence of characters, typically human-readable. They are composed of ASCII or Unicode characters and can be
opened and viewed with a simple text editor. Examples include .txt, .c, .html, .csv.
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

 Binary Files:

These files store data in a non-human-readable, raw binary format. They contain sequences of bytes that represent data structures, images,
audio, or executable code. Special programs are required to interpret and display the content of binary files. Examples
include .jpg, .mp3, .exe, .pdf.

C Program to Copy the Content of One File to Another

#include <stdio.h>
#include <stdlib.h> // Required for exit()

int main() {
FILE *source_file, *destination_file;
char ch;
char source_filename[] = "[Link]"; // Name of the source file
char destination_filename[] = "[Link]"; // Name of the destination file

// Open source file in read mode


source_file = fopen(source_filename, "r");
if (source_file == NULL) {
printf("Error: Could not open source file '%s'.\n", source_filename);
exit(EXIT_FAILURE); // Exit if source file cannot be opened
}

// Open destination file in write mode


destination_file = fopen(destination_filename, "w");
if (destination_file == NULL) {
printf("Error: Could not open destination file '%s'.\n", destination_filename);
fclose(source_file); // Close source file before exiting
exit(EXIT_FAILURE); // Exit if destination file cannot be opened
}

// Copy contents character by character


while ((ch = fgetc(source_file)) != EOF) {
fputc(ch, destination_file);
}

printf("File '%s' copied successfully to '%s'.\n", source_filename, destination_filename);

// Close both files


fclose(source_file);
fclose(destination_file);

return 0;
}

7b) what are the different types of control statements? Explain with example.

Control statements:

Conditional statements in programming are used to execute certain blocks of code based on specified conditions. They are fundamental
to decision-making in programs. Here are some common types of conditional statements:

1. If Statement in Programming:

The if statement is used to execute a block of code if a specified condition is true.

#include <iostream>
using namespace std;
int main()
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

{
int a = 5;
if (a == 5) {
cout << "a is equal to 5";
}
return 0;
}

Output
a is equal to 5

[Link]-else Statement in Programming:

The if-else statement is used to execute one block of code if a specified condition is true, and another block of code if the condition is false.

#include <iostream>
using namespace std;
int main()
{
int a = 10;
if (a == 5) {
cout << "a is equal to 5";
}
else {
cout << "a is not equal to 5";
}
return 0;
}

Output

a is not equal to 5

[Link]-else-if Statement in Programming:

The if-else-if statement is used to execute one block of code if a specified condition is true, another block of code if another condition is true,
and a default block of code if none of the conditions are true.

#include <iostream>
using namespace std;

int main()
{
int a = 15;
if (a == 5) {
cout << "a is equal to 5";
}
else if (a == 10) {
cout << "a is equal to 10";
}
else {
cout << "a is not equal to 5 or 10";
}
return 0;
}

Output
a is not equal to 5 or 10
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

4. Ternary Operator or Conditional Operator in Programming:

In some programming languages, a ternary operator is used to assign a value to a variable based on a condition.

#include <iostream>
using namespace std;

int main()
{
int a = 10;
cout << (a == 5 ? "a is equal to 5"
: "a is not equal to 5");
return 0;
}

Output
a is not equal to 5

5. Switch Statement in Programming:

In languages like C, C++, and Java, a switch statement is used to execute one block of code from multiple options based on the value of an
expression.

#include <iostream>
using namespace std;
int main()
{
int a = 15;
switch (a) {
case 5:
cout << "a is equal to 5";
break;
case 10:
cout << "a is equal to 10";
break;
default:
cout << "a is not equal to 5 or 10";
}
return 0;
}

Output

a is not equal to 5 or 10

Looping Statements:

Looping statements, also known as iteration or repetition statements, are used in programming to repeatedly execute a block of code.
They are essential for performing tasks such as iterating over elements in a list, reading data from a file, or executing a set of instructions a
specific number of times. Here are some common types of looping statements:

For Loop:

The for loop is used to iterate over a sequence (e.g., a list, tuple, string, or range) and execute a block of code for each item in the sequence.

#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 5; i++) {
cout << i << endl;
}
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

return 0;
}

Output
0
1
2
3
4

[Link] loop:

The while loop is used to repeatedly execute a block of code as long as a specified condition is true.
#include <iostream>
using namespace std;
int main()
{
int count = 0;
while (count < 5) {
cout << count << endl;
count++;
}
return 0;
}

Output
0
1
2
3
4

[Link] while loop:

In some programming languages, such as C and Java, a do-while loop is used to execute a block of code at least once, and then repeatedly
execute the block as long as a specified condition is true.
#include <iostream>
using namespace std;
int main()
{
int count = 0;
do {
cout << count << endl;
count++;
} while (count < 5);
return 0;
}

Output
0
1
2
3
4

3. Nested Loops in Programming:

Loops can be nested within one another to perform more complex iterations. For example, a for loop can be nested inside another for loop to
create a two-dimensional iteration.

#include <iostream>
using namespace std;
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

int main()
{
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cout << "i=" << i << " j=" << j << "\n";
}
}
}

Output
i=0 j=0
i=0 j=1
i=1 j=0
i=1 j=1
Each programming language may have its own syntax and specific variations of these looping statements.
Jump Statements in Programming:
Jump statements in programming are used to change the flow of control within a program. They allow the programmer to transfer
program control to different parts of the code based on certain conditions or requirements. Here are common types of jump
statements:

1. Break Statement in Programming:

The break statement is primarily used to exit from loops prematurely. When encountered inside a loop, it terminates the loop's execution and
transfers control to the statement immediately following the loop.

#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++) {
if (i == 5)
break;
cout << i << " ";
}
return 0;
}

Output
01234
2. Continue Statement in Programming:

The continue statement is used to skip the current iteration of a loop and proceed to the next iteration.

#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++) {
if (i % 2 == 1)
continue;
cout << i << " ";
}
return 0;
}

Output
02468

3. Return Statement in Programming:

The return statement is used to exit a function and optionally return a value to the caller.
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

#include <iostream>
using namespace std;
bool isEven(int N) { return N % 2 == 0; }
int main()
{
int N = 5;
if (isEven(N)) {
cout << "N is even";
}
else {
cout << "N is odd";
}
return 0;
}

Output
N is odd

4. Goto Statement in Programming:

Some programming languages support the goto statement, which allows transferring control to a labeled statement within the same function
or block of code. However, the use of goto is generally discouraged due to its potential for creating unreadable and unmaintainable code.

#include <iostream>
using namespace std;
int main()
{
int i = 0;
loopStart:
if (i < 5) {
cout << i << " ";
i++;
goto loopStart;
}
return 0;
}

Output

01234

8a) Define a pointer along with its syntax for declaration and list its use? Write a c program to add sum of elements of an array
using pointer.

A pointer is a variable that stores the memory address of another variable. Instead of holding a direct value, it holds the location in
memory where a value of a specific data type is stored.

Syntax for Declaration:

The general form for declaring a pointer in C is:

type *pointer_name;

Here, type is the data type of the variable whose address the pointer will store (e.g., int, char, float), and pointer_name is the name of the
pointer variable. The asterisk * signifies that it's a pointer.

Examples:

int *ip; // Pointer to an integer


char *cp; // Pointer to a character
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

float *fp; // Pointer to a float

Uses of Pointers:

 Dynamic Memory Allocation:


Pointers are crucial for allocating memory during program execution using functions like malloc(), calloc(), and realloc().
 Arrays and Strings:
Pointers provide an efficient way to traverse arrays and manipulate strings, as array names often decay into pointers to their first element.
 Functions:
Pointers are used to pass arguments by reference to functions, allowing modifications to the original variables within the calling scope.
 Data Structures:
Pointers are fundamental for implementing complex data structures like linked lists, trees, graphs, and queues, where elements are linked by
their memory addresses.
 Direct Memory Access:
Pointers enable direct manipulation of memory, which can be useful for low-level programming and hardware interaction.

C Program to Add Sum of Elements of an Array Using Pointer:

#include <stdio.h>
#include <stdlib.h> // Required for malloc

int main() {
int n, sum = 0;
int *ptr;

printf("Enter the number of elements in the array: ");


scanf("%d", &n);

// Allocate memory for 'n' integers


ptr = (int *)malloc(n * sizeof(int));

// Check if memory allocation was successful


if (ptr == NULL) {
printf("Memory allocation failed!\n");
return 1; // Indicate an error
}

printf("Enter %d elements:\n", n);


for (int i = 0; i < n; i++) {
scanf("%d", (ptr + i)); // Read elements into allocated memory using pointer arithmetic
}

// Calculate the sum using pointer arithmetic


for (int i = 0; i < n; i++) {
sum += *(ptr + i); // Dereference the pointer to get the value at each address
}

printf("Sum of array elements: %d\n", sum);

free(ptr); // Deallocate the dynamically allocated memory


return 0;
}
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

8b) Distinguish between structure and union. Create nested structures with student details such as name, id, department and
calculate their average marks for 3 subjects.

Structure:
 A structure is a user-defined data type that groups related data items of different data types under a single name.
 Each member within a structure is allocated its own distinct memory space.
 All members can be accessed simultaneously, and their values can be stored and modified independently.
 The total size of a structure is the sum of the sizes of its individual members (plus any padding for memory alignment).
Union:
 A union is a user-defined data type where all members share the same memory location.
 Only one member of a union can hold a value at any given time. Storing a value in one member overwrites the values of other
members.
 The size of a union is determined by the size of its largest member, as all members share that same memory space.
 Unions are primarily used for memory efficiency when only one data type needs to be active at a particular instance.

Nested Structures for Student Details and Average Marks Calculation:

#include <stdio.h>
#include <string.h>

// Define a structure for marks


struct Marks {
float subject1;
float subject2;
float subject3;
};

// Define a structure for department details


struct Department {
char deptName[50];
char HOD[50];
};

// Define a structure for student details, nesting Marks and Department


struct Student {
char name[100];
int id;
struct Department studentDept; // Nested Department structure
struct Marks studentMarks; // Nested Marks structure
float averageMarks;
};

int main() {
struct Student s1;

// Input student details


strcpy([Link], "Alice Smith");
[Link] = 101;
strcpy([Link], "Computer Science");
strcpy([Link], "Dr. John Doe");
[Link].subject1 = 85.5;
[Link].subject2 = 90.0;
[Link].subject3 = 78.5;

// Calculate average marks


[Link] = ([Link].subject1 + [Link].subject2 + [Link].subject3) / 3.0;

// Display student details and average marks


printf("Student Name: %s\n", [Link]);
printf("Student ID: %d\n", [Link]);
printf("Department: %s (HOD: %s)\n", [Link], [Link]);
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

printf("Subject 1 Marks: %.2f\n", [Link].subject1);


printf("Subject 2 Marks: %.2f\n", [Link].subject2);
printf("Subject 3 Marks: %.2f\n", [Link].subject3);
printf("Average Marks: %.2f\n", [Link]);

return 0;
}

9) State and explain single and multi-dimensional array with example. Write a C program for transpose of matrix ?

Single-Dimensional Array:

A single-dimensional array is a linear collection of elements of the same data type, stored in contiguous memory locations. Each element is
accessed using a single index, representing its position within the array.

Example:

int numbers[5] = {10, 20, 30, 40, 50};


// 'numbers' is a single-dimensional array of 5 integers.
// numbers[0] is 10, numbers[1] is 20, and so on.

Multi-Dimensional Array

A multi-dimensional array is an array of arrays, representing data in a tabular or grid-like structure (e.g., rows and columns for a 2D array).
Elements are accessed using multiple indices, one for each dimension.

Example:

int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};


// 'matrix' is a 2D array (2 rows, 3 columns).
// matrix[0][0] is 1, matrix[0][1] is 2, matrix[1][2] is 6.

C Program for Transpose of a Matrix

#include <stdio.h>

void inputMatrix(int rows, int cols, int matrix[rows][cols]) {


printf("Enter elements of the matrix:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("Enter element matrix[%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
}

void displayMatrix(int rows, int cols, int matrix[rows][cols]) {


for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}

void findTranspose(int rows, int cols, int originalMatrix[rows][cols], int transposeMatrix[cols][rows]) {


for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transposeMatrix[j][i] = originalMatrix[i][j];
}
}
}
CMS COLLEGE OF ENGINEERING AND TECHNOLOGY
(Affiliated to Anna University, Chennai | Approved by AICTE, New Delhi)
(Accredited by NAAC – ‘A’ Grade | ISO: 9001:2015 Certified)
Appachigoundenpathy, Kummittipathi (PO), Coimbatore – 641 032.

int main() {
int rows, cols;

printf("Enter the number of rows for the matrix: ");


scanf("%d", &rows);
printf("Enter the number of columns for the matrix: ");
scanf("%d", &cols);

int originalMatrix[rows][cols];
int transposeMatrix[cols][rows]; // Transposed matrix will have cols rows and rows columns

inputMatrix(rows, cols, originalMatrix);

printf("\nOriginal Matrix:\n");
displayMatrix(rows, cols, originalMatrix);

findTranspose(rows, cols, originalMatrix, transposeMatrix);

printf("\nTranspose of the Matrix:\n");


displayMatrix(cols, rows, transposeMatrix); // Display with transposed dimensions

return 0;
}

Faculty-in-Charge Approved by

R-Remembering U-Understanding Ap-Applying An-Analyzing Ev-Evaluating Cr-Creating

You might also like