1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【实践课外】14.指针2/6-1 鸡兔同笼问题.md

59 lines
1007 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 6-1 鸡兔同笼问题
《孙子算经》记载:“今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?”
#### 函数原型
```c
int ChickenRabbit(int *chicken, int *rabbit, int head, int foot);
```
说明head 和 foot 为头和脚的数量chicken 和 rabbit 为指示鸡和兔数量的指针。若问题有解,则将鸡和兔的数量保存到 chicken 和 rabbit 所指示的变量中,函数值为 1(真);否则不改变 chicken 和 rabbit 所指示的变量,函数值为 0(假)。
#### 裁判程序
```c
#include <stdio.h>
int ChickenRabbit(int *chicken, int *rabbit, int head, int foot);
int main()
{
int h, f, c, r;
scanf("%d%d", &h, &f);
if (ChickenRabbit(&c, &r, h, f))
{
printf("%d %d\n", c, r);
}
else
{
puts("None");
}
return 0;
}
/* 你的提交代码将被嵌在这里 */
```
#### 输入样例1
```in
35 94
```
#### 输出样例1
```out
23 12
```
#### 输入样例2
```in
30 71
```
#### 输出样例2
```out
None
```