当前位置: 首页 > news >正文

C语言——鸡兔同笼问题

没注释的源代码

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) 
{
  int tou = 10;                      
  int jiao = 36;                      
  int ji_jiao = tou*2;                 
  int tu_jiao = jiao - ji_jiao;       
  int tu = tu_jiao / 2;             
  int ji = tou - tu;                  
  printf("鸡的数量:%d",ji);           
  printf("兔的数量:%d",tu);          
  return 0;
}

注释的源代码

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) 
{
  int tou = 10;                        // 鸡头和兔头一共10只
  int jiao = 36;                       // 鸡脚和兔脚一共36只
  int ji_jiao = tou*2;                 // 全部为鸡时(即兔抬起两只脚时,视为鸡),鸡的脚是头的两倍
  int tu_jiao = jiao - ji_jiao;       // 抬起来的两只脚就是兔子的脚
  int tu = tu_jiao / 2;               // 兔等于抬起来的两只脚的一半,这里用//(整除)而不是/(除)
  int ji = tou - tu;                   // 鸡的数量是总数减去兔的数量
  printf("鸡的数量:%d",ji);           // 输出鸡的数量
  printf("兔的数量:%d",tu);           // 输出兔的数量
  return 0;
}

http://www.lryc.cn/news/486302.html

相关文章:

  • 数据结构王道P234第二题
  • 层归一化和批归一化
  • Spring Cloud Gateway 网关
  • LabVIEW中的UDP与TCP比较
  • 半导体器件与物理篇3 P-N结
  • 深入剖析String类的底层实现原理
  • #其它:面试题
  • 计算机视觉中的双边滤波:经典案例与Python代码解析
  • 【AI日记】24.11.17 看 GraphRAG 论文,了解月之暗面
  • Front Panel Window Bounds 与 Front Panel Window Bounds 的区别与应用
  • 比较TCP/IP和OSI/RM的区别
  • 【Java项目】基于SpringBoot的【招聘信息管理系统】
  • 【论文笔记】LLaMA-VID: An Image is Worth 2 Tokens in Large Language Models
  • 使用Web Storage API实现客户端数据持久化
  • 基于STM32F103的秒表设计-液晶显示
  • ReentrantLock的具体实现细节是什么
  • 【JavaScript】this 指向
  • DB Type
  • python-返回函数
  • python语言基础-5 进阶语法-5.2 装饰器-5.2.1 闭包
  • 用vscode编写verilog时,如何有信号定义提示、信号定义跳转(go to definition)、模块跳转(跨文件跳转)这些功能
  • MQTT+Springboot整合
  • ERROR TypeError: AutoImport is not a function
  • 软考教材重点内容 信息安全工程师 第 3 章 密码学基本理论
  • 微信小程序 https://thirdwx.qlogo.cn 不在以下 downloadFile 合法域名列表中
  • Linux性能优化之火焰图的起源
  • 《Markdown语法入门》
  • Controller Baseband commands速览
  • Redisson 3.39.0 发布
  • 高阶C语言补充:柔性数组