-
array indexing
I have two loops one for inputting numbers and the other for outputting all the numbers in the array except those entered in the first loop I can do this providing the numbers are it order i.e. 1 2 3...
I need to do this in random orderi've got.
int store[25];
int loop,num=0;
for (loop=0;loop<25;loop++)
{
scanf("%d",&store[loop]);
fflush(stdin);
}
for(num=0;num<25;num++)
{
num1++;
if(num1==store[num])
continue;
fputs(store[num],file_ptr);
}
-
Not sure if this is what you want, but it does show the kind of things you can do
Code:
#include <stdio.h>
#define SIZE 5
int main ( ) {
int store[SIZE];
int i, j;
for ( i = 0 ; i < SIZE ; i++ ) {
scanf( "%d", &store[i] );
}
for ( i = 0 ; i < SIZE ; i++ ) {
int seen = 0;
for ( j = 0 ; j < i ; j++ ) { // search all entries before current
if ( store[j] == store[i] ) {
seen = 1;
break;
}
}
if ( !seen ) printf( "%d ", store[i] );
}
return 0;
}