Ask Question, Ask an Expert


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

Bankers algorithmimplement the bankers algorithm for

Banker's Algorithm Implement the Banker's algorithm for deadlock avoidance, that works on a given set of N processes and M resource types (N The input data and result is then displayed on the screen. You may use your pro ...

Write a c program that calculates and prints the average of

Write a C program that calculates and prints the average of two or more salaries entered by the user. The program should first prompt the user to enter the number of salaries to process (make sure: at least 2 salaries mu ...

Assignment a random mazewrite a new c program with the

Assignment (a) Random Maze Write a new C++ program with the following functionality: The program writes a greeting on the screen. Then the program displays a maze of ASCII symbols on the screen. The maze consists of 8 ro ...

1 write a c program that includes a function called lobster

(1) Write a C program that includes a function called lobster() that accepts three arguments: a character and two integers. The character argument is the character to be printed by lobster(). The second argument is the n ...

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

1 we know that from ece 109 to calculate the

1. We know that from ECE 109, to calculate the equivalent resistance of a network of resistors in series in parallel are given by: Write a C++ program that asks the user to input values for resistors (as many as they wou ...

1 three employees in a company are up special pay increase

1. Three employees in a company are up special pay increase. You are given a file, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee ...

Writing a c code its a beginner level code design a class

Writing a C++ code, its a beginner level code. Design a class house that defines a house on a street. A house has a house number and an (x,y) location, where x and y are numbers between -10 and 10. the key member is plot ...

Assignmentwhen writing c programs include comments in your

Assignment When writing C++ programs include comments in your code, make the program readable by indenting, use meaningful variable and function names, and produce meaningful output. This assignment will be to write a bm ...

Write a c program that prompts the user to enter a line of

Write a C program that prompts the user to enter a line of text (up to 50 characters). It should then convert the text entered to uppercase letters and then to lowercase letters, and then to Sentence case. Your program s ...

  • 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

WalMart Identification of theory and critical discussion

Drawing on the prescribed text and/or relevant academic literature, produce a paper which discusses the nature of group

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