2024年4月14日发(作者:)
Linux下的鸡兔同笼
编写一个程序解决“鸡兔同笼”问题。
1. 使用vi编辑器编写以下源代码。(假设该源代码文件名为test.c) # vi test.c
参考程序:
#include
main()
{
int h,f;
int x,y;
printf("请输入头数和脚数:");
scanf("%d,%d",&h,&f);
x=(4*h-f)/2;
y=(f-2*h)/2;
printf("鸡=%d 兔子=%d",x,y);
}
2. 编译。
# gcc test.c -o test
o选项的作用是
______________________________________________________。
3. 运行。
# ./test
运行结果:
请输入头数和脚数:18,48
鸡=12 兔子=6
注:
鸡+兔子=头
2鸡+4兔子=脚
x+y=h
2x+4y=f
发布者:admin,转转请注明出处:http://www.yc00.com/web/1713101289a2183194.html
评论列表(0条)