
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find minimum in an array without using Relational Operators in C++
In this problem, we are given an array arr[] consisting of n positive elements. Our task is to find minimum in an array without using Relational Operators.
Relational operators in programming are those operators which are used to check the relationship between two values. Like == (equals), greater than (>), less than (<), etc.
Let’s take an example to understand the problem,
Input
arr[] = {4, 2, 5, 1, 7}
Output
1
Explanation
The smallest element is 1.
Solution Approach
A simple way to solve the problem is using a loop and check for the minimum element out of all the elements of the array. For finding the minimum element between the two given elements, we can compare which element becomes 0 first when we decrease both by 1.
Program to illustrate the working of our solution,
Example
#include <iostream> using namespace std; int findMin(int a, int b) { int minVal = 0; while (a && b) { minVal++; a--; b--; } return minVal; } int findMinimumElement(int arr[], int n) { int minVal = arr[0]; int i = (n - 1) ; while(i){ minVal = findMin(minVal, arr[i]); i--; } return minVal; } int main() { int arr[] = {4, 2, 5, 1, 7}; int n = sizeof(arr) / sizeof(arr[0]); cout<<"The minimum element is "<<findMinimumElement(arr, n); return 0; }
Output
The minimum element is 1
- Related Articles
- Find maximum in an array without using Relational Operators in C++
- Relational Operators on STL Array in C++
- Relational Operators in C++
- Comparing String objects using Relational Operators in C++
- Relational Set Operators in DBMS
- Basic Operators in Relational Algebra
- Relational Operators in Dart Programming
- Java Relational Operators
- Relational and Logical Operators in C
- Relational and comparison operators in C++
- What are relational operators in C#?
- Extended Operators in Relational Algebra in C++
- What are the relational operators in Java?
- What are relational operators in C language?
- C++ Relational and Equality Operators

Advertisements