0% found this document useful (0 votes)
4 views6 pages

24BCE513 Practical5

The document outlines practical programming tasks related to 1-D and 2-D array manipulations for a computer programming course. It includes code for reading data into an array, calculating the square of its elements, reversing the array, finding the maximum element, and determining the transpose and symmetry of a matrix. The provided C code demonstrates these functionalities through defined functions and a main execution block.

Uploaded by

Janesh Luhar
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)
4 views6 pages

24BCE513 Practical5

The document outlines practical programming tasks related to 1-D and 2-D array manipulations for a computer programming course. It includes code for reading data into an array, calculating the square of its elements, reversing the array, finding the maximum element, and determining the transpose and symmetry of a matrix. The provided C code demonstrates these functionalities through defined functions and a main execution block.

Uploaded by

Janesh Luhar
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/ 6

Name:Hetvi Vanzara

Roll no:24BCE513

Course name:Computer Programming

Course code:0CS501CC23

Practical 5:
Related to 1-D and 2-D array manipulations:
a) Write a program
- To read data from keyboard and store into 1-D array
- To read data from array and copy its square back to another array -
- To reverse all elements of original array
- To find out maximum element of an original array and print its location
b) Write a program to find transpose of a matrix and find whether it is symmetric or not.

a)

Code:

#include <stdio.h>

#define SIZE 5

void readArray(int arr[], int size) {

for (int i = 0; i < size; i++) {

scanf("%d", &arr[i]);

}
void squareArray(int arr[], int result[], int size) {

for (int i = 0; i < size; i++) {

result[i] = arr[i] * arr[i];

void reverseArray(int arr[], int size) {

int temp;

for (int i = 0; i < size / 2; i++) {

temp = arr[i];

arr[i] = arr[size - i - 1];

arr[size - i - 1] = temp;

void findMax(int arr[], int size) {

int max = arr[0], index = 0;

for (int i = 1; i < size; i++) {

if (arr[i] > max) {

max = arr[i];

index = i;

printf("Maximum element is %d at index %d.\n", max, index);


}

int main() {

int arr[SIZE], squaredArr[SIZE];

readArray(arr, SIZE);

squareArray(arr, squaredArr, SIZE);

for (int i = 0; i < SIZE; i++) {

printf("%d ", squaredArr[i]);

printf("\n");

reverseArray(arr, SIZE);

for (int i = 0; i < SIZE; i++) {

printf("%d ", arr[i]);

printf("\n");

findMax(arr, SIZE);

return 0;

Output:
b)
#include <stdio.h>

#define ROWS 3
#define COLS 3

void readMatrix(int matrix[ROWS][COLS]) {


for (int i = 0; i < ROWS; i++) {

for (int j = 0; j < COLS; j++) {


scanf("%d", &matrix[i][j]);
}
}
}

void printMatrix(int matrix[ROWS][COLS]) {


printf("\nTranspose matrix:\n");
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
printf("%d ", matrix[i][j]);
}

printf("\n");
}
}
void transposeMatrix(int matrix[ROWS][COLS], int transpose[ROWS][COLS]) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {

transpose[j][i] = matrix[i][j];
}
}
}

int isSymmetric(int matrix[ROWS][COLS], int transpose[ROWS][COLS]) {

for (int i = 0; i < ROWS; i++) {


for (int j = 0; j < COLS; j++) {
if (matrix[i][j] != transpose[i][j]) {
return 0;
}
}

}
return 1;
}

int main() {
int matrix[ROWS][COLS], transpose[ROWS][COLS];

readMatrix(matrix);

transposeMatrix(matrix, transpose);
printMatrix(transpose);
if (isSymmetric(matrix, transpose)) {
printf("The matrix is symmetric.\n");
} else {

printf("The matrix is not symmetric.\n");


}

return 0;
}

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy