Not Yet Answered # smallest largest

twomers 408 Discussion Starter manzoor 2 n1337 29 Radical Edward 301 William Hemsworth 1,339 William Hemsworth 1,339 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

You could always have them in an array and use min_element and max_element

From site:

```
// min_element/max_element
#include <iostream>
#include <algorithm>
using namespace std;
// snip
int main () {
int myints[] = {3,7,2,5,6,4,9};
// using default comparison:
cout << "The smallest element is " << *min_element(myints,myints+7) << endl;
cout << "The largest element is " << *max_element(myints,myints+7) << endl;
// Snip
return 0;
}
```

0

i know there are other ways but can you tell me is there any other way to find it using relational operators and if statement only not else statement without checking each number in if statement against each other ?

0

Errr...well, if you are dealing with positive integers only, you could construct a loop, then on each iteration through the loop, subtract one from each of the numbers, and the first one to reach 0 is the smallest; the last one to reach 0 is the largest...

hahaha it models the recursive definition of a natural number, but don't do this...lol

0

> using relational operators and if statement only not else statement without

> checking each number in if statement against each other

You've put in too many restrictions. You have to test each number against the other at some point to find the maximum. Using only relational operators and if without else can be done, but as soon as you said "without checking each number in if statement against each other", you make the problem impossible to solve. This is what Edward thought you wanted, but now I'm not sure:

```
int MaxOf3(int a, int b, int c)
{
if (a >= b) {
if (a >= c)
return a;
if (c > a)
return c;
}
if (b > a) {
if (b > c)
return b;
if (c > b)
return c;
}
}
```

0

Heres a way of doing it without < > <= >=

```
#include<iostream>
using namespace std;
int min3(int a, int b, int c) {
for (int i = 0;; i++) {
if (i == a) return a;
if (i == b) return b;
if (i == c) return c;
}
return 0;
}
int main() {
cout << min3(77,24,879); // output 24
cin.ignore();
return 0;
}
```

0

Or without any logical operators:

```
int min3(int a, int b, int c) {
for (int i = 0;; i++) {
if (!(a - i)) return a;
if (!(b - i)) return b;
if (!(c - i)) return c;
}
return 0;
}
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...