Questions about Arrays[] in C.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <conio.h>

int main()
{
	void findMin(int tegers[], int size);  //Function Prototypes
	void findMax(int tegers[], int size);

	int a,b,c,d,e,i;
	int tegers[5] = {a,b,c,d,e};

	for(i=0;i<5;i++)
	{
		clrscr();
		printf("%d numbers remaining...\n", 5 - 1);
		printf("Enter a number: ");
		scanf("%d", &tegers[i]);
	}

	printf("\nThe smallest number is %d", findMin(tegers, 5));
	printf("\nThe largest number is %d", findMax(tegers, 5));

	return 0;
}

void findMin(int tegers[], int size)
{
	//Questionable stuff here...
}

void findMax(int tegers[], int size)
{
	//Questionable stuff here...
}


I was able to input integers in in my arrays now my question is;

1. How to find the smallest number in the teger[] array?
2. How to find the largest number in the teger[] array?
3. I can't make pointer to a pointer to a pointer to a pointer in teger[] array work. Any workaround on this?

Oh and I'm using Borland 5.0 as my compiler. Please don't laugh at me I'm still new at C/C++.
Hi

to find largest number in array you would use something like this

1
2
3
4
5
6
7
8
9
10
11

         int     max = 0;

         for (int i=0;i<size;i++)
         {
                if (tegers[i] > max)
                {
                      max = tegers[i];
                }
         }


for minimum you would do the same but max would become min
and you would need to initialise min to the maximum value allowed
and of cause change the compare to <.

Hope this helps you
Shredded
Shredded is correct.
And there is nothing to laugh in asking question everyone who is expert have to go through learning phase
....................................................
http://www.cprogramming.tk
Don't initialise max to 0 (what if you only have negative numbers?). You better use the first element of the array.

void findMin(int tegers[], int size); Where do you get the result?
Topic archived. No new replies allowed.