Name : G.R.
Harshan
Practical Number 05
Areas covered Single Dimensional Arrays
1. Declare a Single dimensional array with 10 elements. Input the values to the array
and find the followings;
I. Minimum value
II. Maximum value
III. Average value
IV. Reverse order of values
#include <stdio.h>
int main()
{
int arr[10];
int min = 0;
int max = 0;
float sum = 0;
printf("Enter 10 numbers:\n");
for (int i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
sum += arr[i];
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
}
printf("Minimum value: %d\n", min);
printf("Maximum value: %d\n", max);
printf("Average value: %.2f\n", sum / 10.0);
printf("Reverse order: ");
for (int i = 9; i >= 0; i--) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
2. Declare two single dimensional array with the size given by the user and find ,
display the followings;
Scalar Sum ( Adding values of each element of an array)
Vector Sum (Adding values of each relative elements of an array and store
them in third array)
Vector Product (Multiply values of each relative elements of an array and
store them in third array)
Scalar Product (Multiply values of each relative elements of an array and
store them in third array. After placing the values in third array add all the
values)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int size1, size2, i;
printf("Enter the size of the first array: ");
scanf("%d", &size1);
int array1[size1];
printf("Enter the elements of the first array: ");
for (i = 0; i < size1; i++) {
scanf("%d", &array1[i]);
}
printf("Enter the size of the second array: ");
scanf("%d", &size2);
int array2[size2];
printf("Enter the elements of the second array: ");
for (i = 0; i < size2; i++) {
scanf("%d", &array2[i]);
}
// Scalar Sum
int scalarSum = 0;
for (i = 0; i < size1; i++) {
scalarSum += array1[i];
}
printf("Scalar Sum of the first array: %d\n", scalarSum);
// Vector Sum
int vectorSum[size1];
for (i = 0; i < size1; i++) {
vectorSum[i] = array1[i] + array2[i];
}
printf("Vector Sum of the first and second array: ");
for (i = 0; i < size1; i++) {
printf("%d ", vectorSum[i]);
}
printf("\n");
// Vector Product
int vectorProduct[size1];
for (i = 0; i < size1; i++) {
vectorProduct[i] = array1[i] * array2[i];
}
printf("Vector Product of the first and second array: ");
for (i = 0; i < size1; i++) {
printf("%d ", vectorProduct[i]);
}
printf("\n");
// Scalar Product
int scalarProduct = 0;
for (i = 0; i < size1; i++) {
scalarProduct += array1[i] * array2[i];
}
printf("Scalar Product of the first and second array: %d\n", scalarProduct);
return 0;
}