鱼C论坛

 找回密码
 立即注册
查看: 1244|回复: 2

[已解决]函数简单问题

[复制链接]
发表于 2021-12-2 19:42:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Boring1031 于 2021-12-2 19:48 编辑
  1. #include <stdio.h>
  2. #define N 5
  3. int fun(int a[N])
  4. {
  5.         int i,j,k;
  6.        
  7. }
  8. int main(void)
  9. {
  10.         int n,s,a[N];
  11.         for(n=0;n<5;n++)
  12.         {
  13.                 scanf("%d",&a[n]);
  14.         }
  15.         s=fun(a[N]);
  16.         printf("s=%d",s);
  17.        
  18.         return 0;
  19. }
复制代码

中间那一段函数求大佬
最佳答案
2021-12-2 19:57:53
  1. #include <stdio.h>

  2. void f(int arr[], int n){
  3.     if(n >= 0){
  4.         printf("%d ", arr[n]);
  5.         f(arr, n-1);
  6.     }
  7.     else{
  8.         return;
  9.     }
  10.    
  11. }

  12. int main()
  13. {
  14.     int arr[5] = {14, 5, 98, 72, 6};
  15.     f(arr, 4);
  16.     return 0;
  17. }
复制代码
[OY)Q28N66[AALBV$7}(W3U.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-12-2 19:54:17 | 显示全部楼层
  1. #include <stdio.h>

  2. void output(size_t num) {
  3.     if(!num) return;
  4.     printf("%lu", num % 10);
  5.     output(num / 10);
  6. }

  7. int main(void) {
  8.     output(1234); puts("");
  9.     output(5432); puts("");
  10.     output(1204); puts("");
  11.     output(1000); puts("");
  12.     return 0;
  13. }
复制代码


https://fishc.com.cn/forum.php?m ... 313&pid=5659425
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-2 19:57:53 | 显示全部楼层    本楼为最佳答案   
  1. #include <stdio.h>

  2. void f(int arr[], int n){
  3.     if(n >= 0){
  4.         printf("%d ", arr[n]);
  5.         f(arr, n-1);
  6.     }
  7.     else{
  8.         return;
  9.     }
  10.    
  11. }

  12. int main()
  13. {
  14.     int arr[5] = {14, 5, 98, 72, 6};
  15.     f(arr, 4);
  16.     return 0;
  17. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 06:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表