How to use C language to realize encirclement counting
This article mainly introduces "how to use C language to realize circle counting". In daily operation, I believe that many people have doubts about how to use C language to realize circle counting. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to use C language to realize circle counting"! Next, please follow the editor to study!
Encircle the number of problems to solve the first step. Whole logic
1. Start counting from the first person.
two。 Count to the m individual out of line
3. Then start counting from the next person who comes out of the queue.
4. When you count to the m, the individual comes out again. This is repeated until all the people are out of line.
two。 The realization of logic
1. Create an array to record people's information
two。 Use the loop to report the number in turn (when there is only one person left, the loop ends (because there is no need to count, just output it))
3. Output the person who reports to m and mark him (indicates that this person has been dequeued)
4. Finally output the rest of the person.
three。 Implementation of the code # include#include#pragma warning (disable:4996) int main () {int n, m; scanf ("% d% d", & n int & m); int* arr = (int*) malloc (sizeof (int) * (for 1)); / / create an array for (int I = 0; I)