c - given a list of numbers, find the first and last times a certain number is entered -
i need create programme that, when user inputs list of integers, finds position of first , lastly entry of number, , number of times specific number shows up.
the proper output supposed this:
enter number find: 4 come in list of numbers (negative quit): 1 8 4 9 3 4 4 8 2 4 10 3 4 2 4 -1 list contains 15 numbers. first occurrence of '4': 3 lastly occurrence of '4': 15 quite few found!
i have working great except 1 thing: since i'm using scanf take in user input each time, instead of putting numbers on 1 line, this:
1 8 4 9 3 4 4 8 2 4 10 3 4 2 4 -1
it this:
1 8 4 9 3 4 4
etc.
is there way have not start new line each entry?
yeah, if utilize \n
in printf
format string, new line. if don't have character in there, won't. take out , write new line after loop.
likewise, when entering numbers @ prompt, don't press enter after each one. looks supposed come in them separated spaces.
given want display prompt text on same line input, may need flush output too:
printf( "enter list of numbers (negative quit): " ); fflush( stdout ); // input loop. int num; { if( 1 != scanf( "%d", &num ) ) { fprintf( stderr, "bad input\n" ); exit(1); } // input... } while( num != -1 );
c scanf
No comments:
Post a Comment