Hi, i'm new to this forum and i have seen a lot of really useful information given here, so i thought i would give it a shot.
I'm doing a program that is VERY basic and the spec of the program calls for me to have the user input a certain amount of values and I have to display the smallest of the values, the largest of the values and then i have to display the array itself with each value the user input. Each has to be done by main() calling each of these as a separate function. finding and displaying the smallest and largest were fairly easy, but when i get to displaying the array, it displays the number of elements in the array, without the corresponding values...
PLEASE HELP ME!!! THIS HAS ME SO STUMPED!
here's a copy of the program
Code:
#include<stdio.h>
#include<stdlib.h>
#define SIZE 5
int largest(int L[]){
int i,big;
big=L[0];
for (i=1;i<SIZE;i++){
if (L[i]>big){
big=L[i];
}
} return big;
}
int smallest(int S[]){
int i, small;
small=S[0];
for (i=1;i<SIZE;i++){
if (S[i]<small){
small=S[i];
}
}return small;
}
void displayArray(){
int i;
printf("\nHere is your array:\n\n");
printf("You have %i elements in this array.\n",SIZE);
for (i=0;i<SIZE;i++){
//this is where i get stuck!!
printf("In element [%i] is the value %i \n",i+1); //what goes here
}
return i;
}
main (){
int large,i,small,finish;
int element[SIZE];
do{
for (i=0;i<SIZE;i++){
printf("Enter value for element [%i]: ",i+1);
scanf("%i",&element[i]);
}
large=largest(element);
small=smallest(element);
displayArray();
printf("\nthe largest value is: %i\n",large);
printf("the smallest value is: %i\n\n",small);
printf("press 1 to quit: ");
scanf("%i",&finish);
system ("pause");
}
while (finish!=1);
}