0% found this document useful (0 votes)
809 views3 pages

Assignment 1

Uploaded by

namanjaat4186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
809 views3 pages

Assignment 1

Uploaded by

namanjaat4186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

1 Task 1: Pseudocode Development

1. Start
2. Enter a number (let's say "num").
3. If number is even:
a. Assign result to num * num (num squared).
Else:
a. Assign result to num * num * num (num cube).
4. Produce the outcome.
5. Inquire if the user wishes to proceed:
A. if yes, go to step 2.
B. If not, stop the application.
6. Stop

Task 2: Flowchart Creation Design a flowchart that outlines the logic for a
user login process. It should include conditional paths for successful and
unsuccessful login attempts, and a loop that allows a user three attempts
before locking the account.
Task 3: Function Design and Modularization Create a document that
describes the design of two modular functions: one that returns the factorial
of a number, and another that calculates the nth Fibonacci number. Include
pseudocode and a brief explanation of how modularity in programming helps
with code reuse and organization.

Factorial of n

Pseudocode:

def factorial(number):
if number == 0:
return 1
else:
return number * factorial(number - 1)

Described
This function performs a recursive calculation of a number's factorial. It determines whether
the number is zero, in which case it returns one because zero has a factorial of one. If not, it
calls itself recursively, decrementing the number by 1, until it reaches the base case.

Fibonacci Pseudocode:

def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)

Described
The nth Fibonacci number is determined recursively using this function, as explained below.
Since the Fibonacci sequence begins with 0 and 1, it checks to see if n is 0 or 1. If n is 1, it
returns 0 or 1, respectively. If not, it calls itself recursively with n decremented by 1 and n
decremented by 2, adding the results to obtain the nth Fibonacci number.
Modularity in Programming

1 Code reuse: It is the practice of reusing modular functions in various sections of a program
or even in separate applications. For example, you can reuse the above-designed factorial and
Fibonacci functions whenever you need to perform factorial or Fibonacci computations.

2 Maintainability: Modularizing a software makes it easier and less error-prone to make


updates or adjustments. Without affecting the remainder of the software, developers can
concentrate on changing particular modules.

3 Enhanced Readability: Because each module in a modular program has a distinct purpose and
can be examined separately, they are frequently simpler to read and comprehend. This
facilitates other developers' understanding and contribution to the source.

4 Scalability: Modular architecture makes it simple to add new features or functionalities by


constructing new

You might also like