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++

Here are two examplesifcounter7continueifcounter7break1

Here are two examples: if(counter==7) continue; if(counter==7) break; 1. Write a for loop that counts only the odd numbers out of the first five numbers entered from the keyboard, but does not count (skips) the number 7. ...

Write code to create the generator submit your source code

Write code to create the generator. Submit your source code as well as a description of how I could run the program, sample screenshots of the program in action, and the various changes that could be produced through you ...

Write an application that allows the user to enter two

Write an application that allows the user to enter two variables: number (real) and code (character). Calculate the value indicated by the table below: If code is Result A symbol the whole part of the number everything e ...

Cs492 programming assignment-the program must be written in

CS492 Programming Assignment- The program must be written in C or C++, and run on a linux machine. ALL source code you submit must be well documented (documentation is an indicator of understanding!) Programs that cannot ...

Pa 1 word countertabulating basic document statistics is an

PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge of strings, files, loops, and arrays. In this homework, you must write a C++ program that asks the user fo ...

Computer programmingobjectives1 opening a file reading from

Computer Programming Objectives: 1. Opening a file, reading from file, writing to a file and closing a file. 2. Sequential access files handling. 3. Practice C++ programming problems. Note: Carefully read the following i ...

Programming assignment- in this assignment you are

Programming Assignment- In this assignment you are requested to write a C++ program that displays the following colored pyramid on the screen: - The pyramid is 71 characters wide and 21 characters high. - To draw it, you ...

1 write a program to find the sum amp average of the given

1) Write a program to find the sum & average of the given numbers using the while loop. 2) Write a program in C to find the sum and average of the given numbers stored in an array of n values.

Problem 1 you are tasked to write a program that outputs

PROBLEM 1 You are tasked to write a program that outputs the following amplifier system specifications: Voltage amplification: 25 Input voltage: 50 mV Power output: 2.5 W Bandwidth: 15 kHz Type: Class A a. For this progr ...

A write an array implementation of self-adjusting lists in

a. Write an array implementation of self-adjusting lists. In a self-adjusting list, all insertions are performed at the front. A self-adjusting list adds a find operation, and when an element is accessed by a find, it is ...

  • 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

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate