Home > Back-end >  Numbered individuals and a city circle, 37 (1 ~ 37), the first man since 1 number, count to five wer
Numbered individuals and a city circle, 37 (1 ~ 37), the first man since 1 number, count to five wer

Time:03-30

The arithmetic idea for the
Number from the first to the fifth man, fifth man knocked out, and then starting from the sixth man from 1 count, count to five, continue,

code
 include & lt; Stdio. H> 

37//# define length defined length

Int F_Winner (int * p, int m, int num);//declare the function F_Winner
Void OP_Winner (int * p);//declare the function OP_Winne

Void main ()
{
An int array (length),
int i=0;
Int m=0;
//array array initialization
for(i; i {
Array [I]=I + 1;
}
for(i=0; i {
M=F_Winner (array, m, 5);
Array [m]=0;
}
OP_Winner (array);
}
//to find a winner
Int F_Winner (int * p, int m, int num)
{
int count=0;
While (1)
{
If (p [m].=0)
{
count++;
If (num==count)
break;
}
M++;
If (m & gt;=length)
{//overflow, give m
0 assignmentm=0;
}
}
Return m;
}
//output the serial number of the winner
Void OP_Winner (int * p)
{
int i;
for(i=0; i {
If (p [I]!=0)
{
Printf (" % d is a winner, "\ n, p [I]);
}
}
}


Results the

CodePudding user response:

//assume there are n people completely surrounded, personal start counting from the first, at the first m personal time, the first m personal dequeue, 
//and then continue to count from 1 began to count, to the first m personal exit
#include
#include
Int I, k, t;
Int n, m;
The static char f [1001];//0 the seats are not ones, 1 the seat has been ones with
Void main () {
While (1) {
Printf (" Input n m (1000 & gt;=n>=m>=1) : ");
The fflush (stdout);
The rewind (stdin);
If (2==the scanf (" % d % d ", & amp; N, & amp; M)) {
If (1000 & gt;=n & amp; & n>=m & amp; & M>=1) break;
}
}
T=0;//have ones with the total number of
I=1;//seat number
K=1;//the current wants to count the number of
While (1) {
If (==0 f [I]) {
If (m==k) {
t++;
F [I]=1;
Printf (" % 3 d ", I);
If (0==t % 10) printf (" \ n ");
If (t>=n) break;
}
k++; If (k> M), k=1;
}
i++; If (i> N) I=1;
}
Cprintf (" Press any key... ");
getch();
}

CodePudding user response:

The header file: # include

Define functions: int fflush (FILE * stream);
Function description: fflush () will force the data within the buffer to write back to stream specifies the file and stream if the parameter is NULL, fflush () will all open files data update,
Return value: failed to successfully returns 0, returns EOF, the error code stored in errno,
Fflush () can also be used for the standard input (stdin) and standard output (stdout), used to empty the standard input and output buffer,
Stdin is the standard input, namely the standard input, generally refers to the keyboard; Standard input buffer is used to the staging of the content of the input from the keyboard buffer, stdout is standard output, or standard output, generally refers to a display; The standard output buffer is used to display the contents of the buffer, temporary will


Empty the standard output buffer,
Refresh the output buffer, the buffer output to the screen
If in parentheses is already open file pointer, then the content of the output buffer is written to the file pointer to, or removal of the output buffer,
The stdout is the standard output file pointer system definition, by default refers to the screen, that is to write the contents of the buffer on the screen,
But from the code is not to find out what will buffer content, so it didn't work

CodePudding user response:

Rewind to clear the standard input (stdin) key buffer

CodePudding user response:

 fflush () can also be used for the standard input (stdin) and standard output (stdout), used to empty the standard input and output buffer 

The fflush (stdin); Some compilers may effectively under Windows, is not equal to other compilers must also effective; Limited by certain compiler ~
  • Related