CramX Logo
CSC 245 Recursion Lab - Document preview page 1

CSC 245 Recursion Lab - Page 1

Document preview content for CSC 245 Recursion Lab

CSC 245 Recursion Lab

A lab assignment on recursion principles and algorithm design.

Lucy Gray
Contributor
4.8
0
about 1 year ago
Preview (2 of 4 Pages)
100%
Log in to unlock
Page 1 of 2
CSC 245 Recursion Lab - Page 1 preview imageCSC245RecursionLabForeachofthefollowing,writerecursivefunctionstocompletethestatedtasks.Testyourfunctionsbylettingyourmainfunctioncalltherecursivefunctionandreporttheresults.1.Givenanarrayofnintegervalues,computethesumofthevalues.Answer:/****Q1**@paramn*@return*/publicstaticintsum(intn){if(n==0){return0;}elsereturn(n+sum(n-1));}2.Outputthefollowingpatterns:a.********************(annxmrectangle)********************Answer:/****2.afunction**@paramn*@paramm*@return*/publicstaticStringrectangle(intn,intm){if(n==0){return"";}for(inti=0;i<m;i++){System.out.print("*");}System.out.println();returnrectangle(n-1,m);
Page 2 of 2
CSC 245 Recursion Lab - Page 2 preview image
Preview Mode

This document has 4 pages. Sign in to access the full document!