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

Asdskills

The document contains three C programs that perform different operations on an array: finding the maximum element, calculating the sum of elements, and reversing the array. Each program defines a function to execute its specific task and includes a main function to demonstrate the functionality using a sample array. The array used in all examples is {5, 3, 9, 1, 7}.

Uploaded by

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

Asdskills

The document contains three C programs that perform different operations on an array: finding the maximum element, calculating the sum of elements, and reversing the array. Each program defines a function to execute its specific task and includes a main function to demonstrate the functionality using a sample array. The array used in all examples is {5, 3, 9, 1, 7}.

Uploaded by

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

manipulate

max \\
#include <stdio.h>

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


int max = arr[0];

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


if (arr[i] > max) {
max = arr[i];
}
}

return max;
}

int main() {
int arr[] = {5, 3, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);

int max = findMax(arr, size);


printf("Maximum element in the array: %d\n", max);

return 0;
}

calculate the sum of elements \\


#include <stdio.h>

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


int sum = 0;

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


sum += arr[i];
}

return sum;
}

int main() {
int arr[] = {5, 3, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);

int sum = calculateSum(arr, size);


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

return 0;
}

Program to reverse an array: \\


#include <stdio.h>

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


int start = 0;
int end = size - 1;

while (start < end) {


int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;

start++;
end--;
}
}

int main() {
int arr[] = {5, 3, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);

printf("Original array: ");


for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
printf("\n");

reverseArray(arr, size);

printf("Reversed array: ");


for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
printf("\n");

return 0;
}

You might also like