2013计算机上机实习报告 .docVIP

  • 2
  • 0
  • 约2.36万字
  • 约 15页
  • 2016-12-10 发布于北京
  • 举报
改错题 第1题 题目要求 函数fun的功能是:用递归算法计算斐波拉契级数数列中第n项的值。从第l项起,斐波拉契级数序列为1、1、2、3、5、8、13、21、…;例如:当给n输入7,该项的斐波拉契级数值为13。 #include stdio.h long fun(int g) /*************found************/ { switch(g); { case 0:return 0; /***********found*************/ case 1;case 2: return 1; } return (fun(g-1)+fun(g-2)); } main() { long fib; int n; printf(input n: ); scanf(%d,n); printf(n=%d\n,n); fib=fun(n); printf(fib=%d\n\n,fib); } 错误分析 ?语句swich(g);错误,swich(表达式)后不应该带有“;”,应该为:swich(g) ?语句case 1;case 2: return 1;错误,case语句常量后应该是“:”,应该为:case:case:return 1; 第2题 一、题目要求 下列给定程序中,函数fun的功能是:将字符串p中的所有字符复制到字符串b中,要

文档评论(0)

1亿VIP精品文档

相关文档