# largest - smallest number??

Discussion in 'C' started by creative, Jun 11, 2010.

1. ### creativeNew Member

Joined:
Feb 15, 2010
Messages:
87
0
Trophy Points:
0
any one command that automatically detects, for example, 10 of which entered the largest numbers .. or what is the smallest?

and thus may ausgebn then.

so

Code:
```printf ("the smallest number:% i", x)
printf ("the largest number:% i", y)```

2. ### inspirationNew Member

Joined:
Feb 15, 2010
Messages:
85
0
Trophy Points:
0
hi, you can save the pay in a dynamic array, then sort. forward then is the largest and the smallest rear, or the reverse, according as. I think it is also name.max? correct me if I am wrong!

3. ### techmeNew Member

Joined:
Feb 15, 2010
Messages:
86
0
Trophy Points:
0
If the numbers are stored in an array, they can be sorted with qsort easy.

# Include <stdlib.h>

void qsort (....);

4. ### inspirationNew Member

Joined:
Feb 15, 2010
Messages:
85
0
Trophy Points:
0
@techme:
it going with arrayname.max?

5. ### techmeNew Member

Joined:
Feb 15, 2010
Messages:
86
0
Trophy Points:
0
So that nothing goes wrong, i have a small program
added. qsort you still need a comparison function.
Code:
```# Include <stdlib.h>

CompareInt int (const void * p_void1, const void * p_void2)
(
const int * p_int1 = (const int *) p_void1;
const int * p_int2 = (const int *) p_void2;

if (* p_int1 <* p_int2)
return -1;
else if (* p_int1> * p_int2)
return 1;
else
return 0;
)

void main ()
(
ArrayOfInt int [10];
/ * Array show * /
qsort (ArrayOfInt, 10, sizeof (int), CompareInt);
)```

6. ### meyupNew Member

Joined:
Feb 15, 2010
Messages:
102
0
Trophy Points:
0
store in an array and then sort it is cheese ... if the numbers are entered, you can decide but already, what the largest / smallest number is ....

Code:
```# Include <stdio.h>

int main (void)
(
int i, max, min;

scanf ("% d", & i) max = min = i;
while (i! = -1) (
if (i> max) max = i;
if : (i <min) min = i;
scanf ("% d", & i);
)

printf ("Max:% d - Min:% d", max, min);
return 0;
)```

7. ### pankaj.seaNew Member

Joined:
Apr 6, 2009
Messages:
461
13
Trophy Points:
0
Occupation:
Web Developer
Location:
Kolkata
http://ipankaj.net
So actually, I had not known ..

for what: scanf ("% d", & i) max = min = i; .... not me of course!?
and the while loop I think is not necessary ...
Code:
```# Include <stdio.h>

void main (void)
(
int i, max, min, a, b, c;

scanf ("% i% i% i", & a, & b, & c);

(
if (i> max) max = i; => which I Tschegg not know why this is, but no sense and what is% d - so d?
if : (i <min) min = i;
scanf ("% i", & i);
)

printf ("Max:% i - min:% i, max, min);

)```
I would have to do now in my opinion, set, or for the variable i to be taken into account or just pay what the pay compared to improve the transfer eingegbn solln .... how do you das. ..... so i made the variable a, b, c consist and it should be max, and min

8. ### meyupNew Member

Joined:
Feb 15, 2010
Messages:
102
0
Trophy Points:
0
If you want to enter only three numbers, which is probably not a problem. In my solution I assumed that you have to Enter as many numbers. Therefore the loop.

A statement such as
Code:
```min = max = i;

```
says only that min and max get the value for i. Two's If necessary, a etvl. set new min or max value. But that is only necessary if you want to process multiple inputs.

If you actually reads only three values, then the whole thing is much easier. You have to stop only compare a, b and c each other and Sun set the maximum and minimum value ...

9. ### meyupNew Member

Joined:
Feb 15, 2010
Messages:
102
0
Trophy Points:
0
oih yes...
you get used void main (void ab).

10. ### pankaj.seaNew Member

Joined:
Apr 6, 2009
Messages:
461
13
Trophy Points:
0
Occupation:
Web Developer
Location:
Kolkata
http://ipankaj.net
no, I have to pay out of 10 (times also could be more) to spend the max and min number Lassner ....

Compare what each other is for the special?

but your code would not work ...... or rather I do not know how I pay any of - to enter in the code to integrate ....

11. ### meyupNew Member

Joined:
Feb 15, 2010
Messages:
102
0
Trophy Points:
0
Then you need ne loop ...

As always compare - as you type things and everything is ok ..
Hmmm ... I think I have an error. Simply compile times and in the console (Windows users - start right?) And numbers in sequence to enter ....

12. ### pankaj.seaNew Member

Joined:
Apr 6, 2009
Messages:
461
13
Trophy Points:
0
Occupation:
Web Developer
Location:
Kolkata
http://ipankaj.net
nÃ¶ I use console wizard ....

why do you always take place ...% d% i?

and so I like to go the little Schnall .... I'll give 10 as a pay does happen ... but nothing (if it were somehow logical that one ne max. no. pay to enter the setting you can ... or I can yes, ever the press enter key and the program does not know whether it can finally break the max, min heraussuchn number )....... or one defines the press at a certain button, the program the max, min picks out a number, would it?

it would be nice if you one-nothing like me, it could explain a little bit closer

but is really nice that you answer is always something

Joined:
Feb 15, 2010
Messages:
102