hi all, i need help with this problem, i seem to get compile errors as well as logic errors in my duplicate function, any help would be appreciated..
Code:
/* Use a single-subscripted array to solve the following problem
** Read in 20 numbers, each of which is between 10 and 100, inclusive.
** As each number is readm print it only if it is not a duplicate
** of a number already read. Provide for the "worst case" in which
** all 20 numbers are different. Use the smallest possible array to solve
** this problem.
*/
#include <stdio.h>
#define SIZE 20
int duplicate( int num[] );
int main()
{
int i, numbers[ SIZE ];
printf( "Enter 20 numbers between 10 and 100: " );
for ( i = 0; i <= SIZE - 1 && scanf( "%d", &numbers[i] ) == 1; i++ )
duplicate( numbers[ i ] );
}
int duplicate( int num[] )
{
int i, hold;
for ( i = 0; i <= SIZE - 1; i++ )
if ( num[i] == num[i+1] ) {
hold = num[i];
else
hold = num[i+1];
}
printf( "%3d\n", num[ i ] );
}