- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to decrease even numbers in an array

Suppose, we are given an array 'arr' of size n that contains positive integer numbers. We have to find the even numbers and decrease them by 1. We print out the array after this process.

So, if the input is like n = 7, arr = {10, 9, 7, 6, 4, 8, 3}, then the output will be 9 9 7 5 3 7 3.

## Steps

To solve this, we will follow these steps −

for initialize i := 0, when i < n, update (increase i by 1), do: if arr[i] mod 2 is same as 0, then: (decrease arr[i] by 1) print(arr[i]) print a new line

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; #define N 100 void solve(int n, int arr[]) { for (int i = 0; i < n; i++){ if (arr[i] % 2 == 0) arr[i]--; cout<< arr[i] << " "; } cout<< endl; } int main() { int n = 7, arr[] = {10, 9, 7, 6, 4, 8, 3}; solve(n, arr); return 0; }

## Input

7, {10, 9, 7, 6, 4, 8, 3}

## Output

9 9 7 5 3 7 3

- Related Questions & Answers
- How to pull even numbers from an array in MongoDB?
- Repeating only even numbers inside an array in JavaScript
- Finding even length numbers from an array in JavaScript
- Returning an array containing last n even numbers from input array in JavaScript
- How to find the Odd and Even numbers in an Array in java?
- How to get the sum of the numbers in even positions in an array?
- Decrease Elements To Make Array Zigzag in Python
- Odd even sort in an array - JavaScript
- How to separate even and odd numbers in an array by using for loop in C language?
- Even numbers at even index and odd numbers at odd index in C++
- How to create a function which returns only even numbers in JavaScript array?
- JavaScript code to print last element of an array
- Average of even numbers till a given even number?
- 8085 program to add numbers in an array
- How to decrease size of a string by using preceding numbers - JavaScript?

Advertisements