Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void reverseArray(int arr[], int size) {
- int start = 0;
- int end = size - 1;
- while (start < end) {
- // Swap elements at start and end indices
- int temp = arr[start];
- arr[start] = arr[end];
- arr[end] = temp;
- // Move towards the center of the array
- start++;
- end--;
- }
- }
- int main()
- {
- int numbers[5] = { 2,5,8,10,15 };
- int sum = 0;
- int max = 0;
- int input;
- int flag;
- //array size
- int arr = sizeof(numbers) / sizeof(int);
- //cout << arr;
- for (int i = 0; i < arr; i++)
- {
- sum = numbers[i] + sum;
- }
- cout << "Sum of the array is: " <<sum <<"\n";
- cout << "Avg of the array is: " << sum/arr << "\n";
- for (int i = 0; i < arr; i++)
- {
- if (numbers[i] > max)
- {
- max = numbers[i];
- }
- }
- cout << "The max element of the array is: " << max << "\n";
- cout << "Your number is: " << "\n";
- cin >> input;
- for (int i = 0; i <arr; i++)
- {
- if (input == numbers[i])
- {
- flag = 1;
- break;
- }
- else flag = 0;
- }
- if (flag == 1)
- {
- cout << "Your number is in the array!" << "\n";
- }
- else cout << "Your number is not in the array!" << "\n";
- //smqna na 3ti element v masiva i otpechatwane
- for (int i = 0; i <arr; i++)
- {
- if (i == 2)
- {
- numbers[2] = 20;
- }
- cout << numbers[i] << " ";
- cout << "\n";
- }
- reverseArray(numbers, arr);
- // Print the reversed array
- cout << "Reversed Array: ";
- for (int i = 0; i < arr; i++) {
- cout << numbers[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement