# coding-example **Repository Path**: dongliangxie/coding-example ## Basic Information - **Project Name**: coding-example - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-25 - **Last Updated**: 2025-06-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🔢 尾递归斐波那契数列实现 这是一个使用C语言实现的高效斐波那契数列计算程序,采用尾递归技术实现O(1)空间复杂度。 ## ✨ 特性 - 🚀 **尾递归实现** - 空间复杂度O(1),避免栈溢出 - ⚡ **高效计算** - 编译器可优化为循环 - 🎯 **命令行友好** - 支持命令行参数输入 - 🛠️ **VS Code集成** - 完整的编译和调试配置 ## 📋 项目结构 ``` ├── fibonacci.c # 主程序源代码 ├── build_and_run.bat # Windows批处理编译脚本 ├── build_and_run.ps1 # PowerShell编译脚本 ├── .vscode/ │ ├── tasks.json # VS Code编译任务配置 │ └── launch.json # VS Code调试配置 ├── .gitignore # Git忽略文件配置 └── README.md # 项目说明文档 ``` ## 🚀 快速开始 ### 编译程序 使用GCC编译器: ```bash gcc -o fibonacci.exe fibonacci.c ``` 或使用VS Code任务: - 按 `Ctrl+Shift+P` - 选择 "Tasks: Run Task" - 选择 "C/C++: gcc.exe build active file" ### 运行程序 ```bash # 语法: ./fibonacci.exe <斐波那契位置> <第二个数字> ./fibonacci.exe 10 5 ``` 输出示例: ``` 第一个数字: 10 第二个数字: 5 两数之和: 15 第10个斐波那契数: 55 ``` ## 🧮 算法说明 ### 尾递归实现 程序使用尾递归技术实现斐波那契数列计算: ```c int fibonacci_helper(int n, int count, int prev, int current) { if (count == n) { return current; } return fibonacci_helper(n, count + 1, current, prev + current); } ``` ### 复杂度分析 - **时间复杂度**: O(n) - **空间复杂度**: O(1) - 尾递归优化后不会消耗额外栈空间 ### 优势 1. 避免普通递归的栈溢出问题 2. 编译器可优化为循环代码 3. 内存使用效率高 4. 适合计算大数值的斐波那契数 ## 🛠️ 开发环境 ### 依赖项 - GCC编译器 (MinGW-w64) - Git版本控制 - VS Code (可选,用于开发) ### VS Code扩展 - C/C++ Extension Pack ### 编译器安装 使用Chocolatey安装MinGW: ```powershell choco install mingw -y ``` ## 📊 测试用例 | 输入位置 | 斐波那契数 | 验证 | |---------|-----------|------| | 0 | 0 | ✅ | | 1 | 1 | ✅ | | 5 | 5 | ✅ | | 10 | 55 | ✅ | | 15 | 610 | ✅ | ## 🤝 贡献 欢迎提交Issue和Pull Request来改进这个项目! ## 📄 许可证 本项目使用MIT许可证。 ## 👨‍💻 作者 项目创建于 2025年6月25日