1. Write a program to store integer elements in an array named test of size 10 with initial values (5,9,57,3,9,21,57,6,9,3) and print it.
2. Modify the program to read to display the array contents in reverse order.
3. Modify the program to find the sum of all elements of the array.
4. Modify the program to copy the elements from the test array into another array named testcopy.
8. Modify the programs to count and display the frequency of each element of array test.
9. Modify the program to find the maximum and minimum element in array test.
#include <iostream>
using namespace std;
int main()
{
int test[] = { 5, 9, 57, 3, 9, 21, 57, 6, 9, 3 };
int size = 10;
cout << "Initial array: ";
for (int i = 0; i < size; i++)
{
cout << test[i] << " ";
}
cout << endl << "Reverse array: ";
for (int i = size - 1; i >= 0; i--)
{
cout << test[i] << " ";
}
int sum = 0;
for (int i = 0; i < size; i++)
{
sum += test[i];
}
cout << endl << "Sum of all elements is: " << sum << endl;
int testcopy[10];
for (int i = 0; i < size; i++)
{
testcopy[i] = test[i];
}
cout << "Copy array: ";
for (int i = 0; i < size; i++)
{
cout << testcopy[i] << " ";
}
int clone[100];
for (int i = 0; i < 100; i++)
{
clone[i] = 0;
}
for (int i = 0; i < size; i++)
{
clone[test[i]]++;
}
cout << endl;
for (int i = 0; i < 100; i++)
{
if (clone[i] != 0)
{
cout << "Element " << i << " meet in test array: " << clone[i] << " times." << endl;
}
}
int min, max;
min = max = test[0];
for (int i = 1; i < size; i++)
{
if (test[i] > max) max = test[i];
if (test[i] < min) min = test[i];
}
cout << "Min value in test array is: " << min << endl;
cout << "Max value in test array is: " << max << endl;
system("pause");
return 0;
}
Comments
Leave a comment