C language to solve the fox's problem of finding rabbits

Source: Internet
Author: User

Around the top of the mountain there are 10 holes, a rabbit and a fox live in their own hole, the fox always want to eat rabbits, one day the rabbit said to the fox, you want to eat I have a condition, you first put the hole number 1 to 10, you start from the 10th hole, first to the 1th hole looking for me, the second every hole to find me, the third time two holes to find me And so on, and so on, if you can find me you can feast on a meal, not found before I can not stop, fox think only 10 holes, the number of search for unlimited, which can not find the truth, agreed to the conditions, the results of the Fox ran faint in the past also did not find rabbits, ask the rabbit to hide in which hole. The fox can be assumed to have been found 1000 times in the program.

The code is as follows:

#include <stdio.h>intMain () {inthole[Ten]={1,2,3,4,5,6,7,8,9,Ten};inti,j=0, index; for(i=0;i< +; i++) {J=j+i+2; Index=j%Ten; Hole[index]=1; } for(i=0;i<Ten; i++)    {    if(hole[i]!=1) printf ("Rabbit is at the hole%d\n", Hole[i]); }return 0;}

The results show that the Fox could not find her as long as the rabbit was in hole No. 2479.

C language to solve the fox's problem of finding rabbits

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.