Thread: C programming
View Single Post
Old 07-18-11, 03:23 AM   #11
PETAPAL
Registered User
 
Join Date: Jul 2011
Posts: 1
Default Re: C programming

#include <stdio.h>
#define MAX 20

int main()
{
int a[ MAX ] = { 0 }; /* user input */
int i; /* counter */
int j; /* counter */
int k = 0; /* number of integers entered */
int duplicate; /* notify of duplicates */
int value;

printf( "Enter 20 numbers between 10 - 100;\n" );

/* ask user for 20 numbers */
for ( i = 0; i <= MAX - 1; i++ ){

duplicate = 0;
scanf( "%d", &value);

/* decide if integer is duplicate */
for ( j = 0; j < k; j++ ) {

/* notify and stop loop if duplicate */
if ( value == a[ j ] ) {
duplicate = 1;
break;
{ /* end if */



/* enter number into array if it's not a duplicate */
if ( !duplicate )

a[ k++ ] = value;

} /* end if */
PETAPAL is offline