In a lap number 3 exit last person location question--c Language Rectification Edition Exercise 8.5

Source: Internet
Author: User

There are n individuals in a circle, order automatic arranging. Starting from the first person (from 1 to 3 count off), where 3 of the people out of the circle, ask the last left is the original number of places


/******************************************************e8.5plan: Can not cycle shout 1 to 3, Replace the Create----------------------------with the sum of multiples of 3 by:     idooi liutime:    2015/10/15-1500----------------------------------******************************************************/ #include  <stdio.h> #include  <stdlib.h>int expthree (int n, int  Manarray[]); Int main (void) {    int nman;        //how many people    char *pman;     //the  array    int sitelast;   //the last person ' S site     int i;    printf ("please input how many  People:\n "); &NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d ",  &nman);     pman=malloc (nMan* sizeof (char)); &NBSP;&NBSP;&NBSP;&NBSP;//ASSIGNMENT&NBSP;&NBSP;&NBSp; for (i=0; i<nman; i++)         * (pMan+i) = ' Y ';     sitelast=expthree (Nman, pman);     printf ("The last  One\ ' s site is %d\n ",  sitelast);     free (PMan);     return 0;} Int expthree (int n, int manarray[]) {    int i, j;     int sitelast;   //the last person ' s site     int flag=0;     //Count off    int k;     for (i=0; i<n; i++)     {         k=0;        //for check how many  people last        for (j=0; j<n; j++)          {            if (manArray[j ]== ' Y ')                 k++;             siteLast=j;         }        if (k==1)          //Only one person             break;        if (manarray[i]== ' Y ')          {            flag++;      //The person who in the team take the  next number            //if the  Person ' S&NBSP;NUMBER&NBSP;IS&NBsp;divisible by 3, take out of the team             if (flag%3==0)                  manarray[i]= ' N ';        }     }    return sitelast;}


In a lap number 3 exit last person location question--c Language Rectification Edition Exercise 8.5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.