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

Ada

The document contains three C programs: one for performing a sequential search of an element in an array, another for finding the maximum element in an array, and a third for performing matrix multiplication. Each program includes functions to execute the respective tasks, along with user input for array or matrix dimensions and elements. The programs also handle output to display results based on user queries.

Uploaded by

abhiabhishek7339
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)
5 views6 pages

Ada

The document contains three C programs: one for performing a sequential search of an element in an array, another for finding the maximum element in an array, and a third for performing matrix multiplication. Each program includes functions to execute the respective tasks, along with user input for array or matrix dimensions and elements. The programs also handle output to display results based on user queries.

Uploaded by

abhiabhishek7339
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
You are on page 1/ 6

ADA

1.develop a c program to perform sequential search of an element

#include <stdio.h>

// Function to perform sequential search

int sequentialSearch(int arr[], int size, int key) {

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

if (arr[i] == key) {

return i; // Return the index if found

return -1; // Return -1 if not found

int main() {

int n, key, result;

// Get the number of elements

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

scanf("%d", &n);

int arr[n];

// Get the array elements

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

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

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

// Get the key to search

printf("Enter the element to search: ");

scanf("%d", &key);

// Perform search

result = sequentialSearch(arr, n, key);

// Display result

if (result != -1) {

printf("Element %d found at index %d.\n", key, result);

} else {

printf("Element %d not found in the array.\n", key);

return 0;

2. To find a maximum element in the given array

#include <stdio.h>

// Function to find the maximum element in an array

int findMaximum(int arr[], int size) {

int max = arr[0]; // Assume first element is the maximum

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

if (arr[i] > max) {

max = arr[i]; // Update max if a larger element is found


}

return max;

int main() {

int n;

// Get the number of elements

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

scanf("%d", &n);

int arr[n];

// Get the array elements

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

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

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

// Find and display the maximum element

int maxElement = findMaximum(arr, n);

printf("The maximum element in the array is %d.\n", maxElement);

return 0;

3.to perform matrix multiplication


#include <stdio.h>

// Function to perform matrix multiplication

void multiplyMatrices(int firstMatrix[][10], int secondMatrix[][10], int result[][10], int row1, int col1, int
row2, int col2) {

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

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

result[i][j] = 0;

for (int k = 0; k < col1; k++) {

result[i][j] += firstMatrix[i][k] * secondMatrix[k][j];

int main() {

int row1, col1, row2, col2;

// Get matrix dimensions

printf("Enter rows and columns for first matrix: ");

scanf("%d %d", &row1, &col1);

printf("Enter rows and columns for second matrix: ");

scanf("%d %d", &row2, &col2);

// Check if multiplication is possible

if (col1 != row2) {

printf("Matrix multiplication not possible. Column of first matrix must be equal to row of second
matrix.\n");
return 1;

int firstMatrix[10][10], secondMatrix[10][10], result[10][10];

// Get first matrix elements

printf("Enter elements of first matrix:\n");

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

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

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

// Get second matrix elements

printf("Enter elements of second matrix:\n");

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

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

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

// Perform matrix multiplication

multiplyMatrices(firstMatrix, secondMatrix, result, row1, col1, row2, col2);

// Display result

printf("Resultant matrix:\n");

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


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

printf("%d ", result[i][j]);

printf("\n");

return 0;

You might also like