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

Array PROGRAMS

The document contains four C programs that perform different operations on arrays: sorting an array in ascending order, finding the largest element, calculating the sum of elements, and displaying the number of elements. Each program prompts the user for the size and elements of the array, processes the data, and outputs the result. The code snippets are structured with standard input and output functions.

Uploaded by

thanoojpamanji
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)
15 views2 pages

Array PROGRAMS

The document contains four C programs that perform different operations on arrays: sorting an array in ascending order, finding the largest element, calculating the sum of elements, and displaying the number of elements. Each program prompts the user for the size and elements of the array, processes the data, and outputs the result. The code snippets are structured with standard input and output functions.

Uploaded by

thanoojpamanji
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/ 2

ARRAY : ​

// 1. Sort array in ascending order


#include <stdio.h>
void sort(int arr[], int n) {
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int main() {
int arr[100], n;
printf("Enter size: ");
scanf("%d", &n);
printf("Enter elements: ");
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sort(arr, n);
printf("Sorted array: ");
for (int i = 0; i < n; i++) printf("%d ", arr[i]);
return 0;
}

c
CopyEdit
// 2. Find largest element in an array
#include <stdio.h>
int main() {
int arr[100], n, max;
printf("Enter size: ");
scanf("%d", &n);
printf("Enter elements: ");
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
max = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > max) max = arr[i];
printf("Largest element: %d\n", max);
return 0;
}
c
CopyEdit
// 3. Find sum of array elements
#include <stdio.h>
int main() {
int arr[100], n, sum = 0;
printf("Enter size: ");
scanf("%d", &n);
printf("Enter elements: ");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
sum += arr[i];
}
printf("Sum of elements: %d\n", sum);
return 0;
}

c
CopyEdit
// 4. Find number of elements in an array
#include <stdio.h>
int main() {
int arr[100], n;
printf("Enter size: ");
scanf("%d", &n);
printf("Number of elements: %d\n", n);
return 0;
}

You might also like