1、Programming In C Once, Einstein gave his friend such a mathematical problem: There is a long ladder, if each step spans 2 ladders, 1 ladder is left; Each step spans 3 ladders, with 2 ladders remaining; Each step spans 5 ladders, with 4 ladders remaining; Each step spans 6 ladders, with 5 ladders rem
2、aining. Only when each step spans 7 ladders, it is exactly the end, and there is no one left. How many steps does the ladder have? Question 1: Einstein steps. Code #includestdio.h void main() int i; for(i=1 ; ; i+) if(i%2=1&i%3=2&i%5=4&i%6=5&i%7=0) break; printf(至少有 %d级台阶 n,i); Question 2: One hundr
3、ed yuan buy one hundred chickens. Given that rooster is worth 5 yuan each, hen is 3 yuan each while 3 chicks are 1 yuan, if you want to buy 100 chickens with 100 yuan, then how many roosters, hens and chicks to buy? Analysis(Exhaustive method): Set the number of roosters, hens, and chicks as x, y, a
4、nd z Given a total of 100 yuan to buy 100 chickens Value range of x、 y、 z x: y: z: 0-20 033 0100 x y z 100 5x3y z/3100 int x,y,z,j=0; printf(Following are possible plans :n); for(x=0;x=20;x+) for(y=0;y=33;y+) z=100-x-y; if(z%3=0&5*x+3*y+z/3=100) printf(%2d:cock=%2d hen=%2d chicken=%2dn,+j,x,y,z); Co
5、de Exhaustive method/Enumeration When using the programming method, we need to determine the general scope of the answer according to some conditions of the question, and we need to verify all possible situations one by one within this scope. If a certain situation is verified to meet all the condit
6、ions of the question, it is a solution to the problem. If it cannot meet all the conditions of the problem after verification, then the problem has no solution. Question 3: Fibonacci sequence. Fibonacci sequence The first and second Numbers are 1, 1 From the third number, you take the sum of the fir
7、st two 1 1 2 3 5 8 13 21 34 . Background : This is an interesting classical mathematics question.If a pair of little rabbits can give birth to a new pair of rabbits every month, and each pair of new rabbits will give birth to another pair of new rabbits in the third month after birth, assuming that
8、no death occurs, how many pairs of rabbits can be bred in a year? 1 n 2 f n f n 1 f n 2 n 2 1 n 1 1 n 2 n 1 f n 2 n 2 Iterative method #include int main() long f1,f2,fn; int i; f1 = f2 = 1; printf(%ldt%ldt,f1,f2); /求余下的 Fibonacci数 return 0; for(i=3; i=40; i+) fn = f1 + f2; printf(%ldt,fn); if(i % 5=0) printf(n); f1 = f2; f2 = fn; f n 1 n 1 f i fn f1 f2 3 4 5 2 3 5 1 1 2 3 1 2 3 5 5 8 6 7 8 . Programming In C