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

Discussionkeyboard versus file input please respond to the

Discussion "Keyboard versus File Input" Please respond to the following: • Suppose you are designing a C++ application that needs to capture user input specifically via a keyboard or from a file. Determine the method tha ...

Modules in c are called functions c programs are typically

Modules in C are called functions. C programs are typically written by combining user created functions as well as "pre-packaged" functions found in the C Standard Library. For instance, printf() is a function that is fo ...

Design implement test and debug a c program to simulate the

Design, implement, test, and debug a C# program to simulate the rolling of two dice 100 times. Whenever the two dice display the same number, the program should show the roll sequence number (e.g. the 10th roll) and the ...

Intro to programming in c programming assignmentassignment

Intro to Programming in C Programming Assignment Assignment purpose: User defined functions, pointers, Menu driven program A Company needs to create software for their new line of phone applications. Customers will have ...

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

1 write a c program that allows the user to create a test

1. Write a C++ program that allows the user to create a test bank of questions 2. The program should first ask the user how many questions he or she wishes to create. 3- The user should now be prompted for all informatio ...

Programming assignment 5write a c program that allows the

PROGRAMMING ASSIGNMENT #5 Write a C program that allows the user to make some banking transactions. The program should first prompt the user to enter the current balance of his/her bank account (in dollars and cents, not ...

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

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

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

  • 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