Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

problem 1) Illustrate that how iteration works in programming languages by writing programs given below.

a) A program to sum number of integers from 1 to a given number n.

b) A program that sums the contents of a integer list or array.

c) Transform the following for loop into a while loop (which does the same thing as the for loop):

for i in range(1,10):
print "i = ", i

d) Transform the following while loop into a for loop (which does the same thing as the while loop):

i = 20
while (i > 0):
print "i = ", i
i =- 1

a) What do you mean by a recursive function?

b) The iterative function given below returns the sum of all elements in a list. For instance, given the list [1, 2, 3] the function will return 1+2+3 or 6. Re-prepare the function as a recursive function.

def sum(arg):
result = 0
for i in arg:
result += i
return result

c) The code given below implements a recursive function in Python called foobar. What does foobar function do? prepare a line of code that calls the foobar function with a appropriate argument and state what the return value will be.
def foobar(arg):

if arg == []:
return arg
else:
return foobar(arg[1:]) + [ arg[0] ]

d) The following code implements two mutually recursive functions – functions that call each other:

def ise(n):
if n==0: return True
else: return iso(n-1)
def iso(n):
if n==0: return False
else: return ise(n-1)

What will the following function calls return:

i) iso(3)
ii) iso(2)
iii) ise(3)
iv) ise(2)

What do the functions iso and ise perform?

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M910511

Have any Question? 


Related Questions in C/C++

Projectdecision statementsdirections read carefully and

Project: Decision Statements Directions (Read CAREFULLY and follow COMPLETELY): - Create the following programs in C++ that perform the purpose described and show the sample output (with user input where applicable). - I ...

Assignmentthis is the programthis program will use 2

Assignment This is the program: This program will use 2 different data structures to perform the same tasks; a vector and a dynamically sized array Write a complete C++ program that will: Declare a vector of integers wit ...

Assignmentpart acomplete the following questionswrite c

Assignment Part A Complete the following questions: Write C++ code to open a document with the name Hello.txt, place the message "Hello, World!" in the document, and exit the document. Re open the file you closed, and re ...

Transaction processing system tpsxyz electronics is one of

Transaction Processing System (TPS) XYZ Electronics is one of the most popular electronics companies In Sultanate of Oman the company offers affordable electronic gadgets such as mp3 players, portable movie players, mobi ...

C projectphase 11- you need to take input from user study

C project Phase 1 1- You need to take input from user study year (proper value check from 1 to 4) 2- Take input semester (proper value check 1 to 8) 3- Calculate GPA (use Loop, calculate GPA for semester 1,2,3...) Exampl ...

Computer scienceyou have gathered your information on the

Computer Science You have gathered your information on the AI for the Tic-Tac-Toe game and began to develop your own ways to improve it using C++. Now, it's time to present your findings in a final paper. Remember that y ...

Discussionwhile loops versus for loops please respond to

Discussion "While Loops versus For Loops" Please respond to the following: • Suppose you are writing a C++ program that plays a commercial video continuously within a kiosk at your favorite shopping mall within your home ...

Intro to programming in c assignmentsince this is the last

Intro to Programming in C Assignment Since this is the last assignment, there will be no late submission. All programs must be electronically submitted by 5:00pm on Tuesday, December 2nd with NO EXCEPTIONS in order to re ...

Assignmentoverviewthis assignment consists of implementing

Assignment Overview This assignment consists of implementing an application using the techniques learned in the first half of the course. Examples on how to use file operations, random number generation, the standard tem ...

Cosci 21a programming assignmentpurpose experience with

COSCI 21a, Programming Assignment Purpose: Experience with some basic data structures, including circular queues, linked lists, hash tables, and specifically with pointers and the associated dynamic memory allocation. Pr ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen