Developing Algorithms for Generating Square Patterns, Study Guides, Projects, Research of Programming Languages

A lab report on developing an algorithm to generate a pattern of squares for different input values of n (from 0 to 5). The report follows a four-step algorithm development process: working through an example, writing down the steps, generalizing the algorithm, and testing it. The algorithm involves filling the grid with red, blue, and green squares based on the values of x and y coordinates and whether n is even or odd. The document also includes a post-lab task to write a program that takes an integer input from the user and determines whether it is even or odd. This lab report could be useful for students studying computer programming, algorithms, and problem-solving techniques, particularly in the context of electrical and computer engineering.

Typology: Study Guides, Projects, Research

2023/2024

Uploaded on 05/26/2024

ali-mumtaz-1
ali-mumtaz-1 🇵🇰

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAMMING FUNDAMENTAL(CSC-103)
NAME Ali Mumtaz
Maaz ajmal
ENROLLMENT FA23-EEE-010
FA23-EEE-022
SUBMISSION DATE 27/3/2024
SUBMITTED TO Dr.Irfan Ullah
SECTION EEE-1
DEPARTMENT OF ELECTRICAL AND
COMPUTER ENGINEERING
Lab-Report 2
pf3
pf4
pf5

Partial preview of the text

Download Developing Algorithms for Generating Square Patterns and more Study Guides, Projects, Research Programming Languages in PDF only on Docsity!

PROGRAMMING FUNDAMENTAL(CSC-103)

NAME Ali Mumtaz Maaz ajmal ENROLLMENT FA23-EEE- FA23-EEE- SUBMISSION DATE 27/3/ SUBMITTED TO Dr.Irfan Ullah SECTION EEE-

DEPARTMENT OF ELECTRICAL AND

COMPUTER ENGINEERING

Lab-Report 2

In Lab

In-Lab Task 1

Q: Develop an Algorithm

Following figure shows a pattern of squares generated for different input values of N (for N=0 to N=5). Develop a general algorithm to fill in the grid for any input N. Use the 4 step process that was discussed in the class (and is given below for reference) The four – step algorithm development process:

**1. Work an example yourself.

  1. Write down what you just did.
  2. Generalize your steps.
  3. Test your algorithm.**

N Red Blue Green x y x y x y (^0 0 0 0 1 1 ) 1 0 1 1 1 0 2 1 0 - - 2 0 2 0 2 0 3 1 2 1 1 2 1 2 1 2 0 - - - - 3 0 3 1 3 0 4 1 2 3 1 2 2 2 1 - - 4 0 3 0 - - - - 4 0 4 0 5 1 4 1 3 2 3 3 2 2 2 4 1 5 0 3 1 - - - - 4 0 - - - - 5 0 5 1 5 0 6 1 4 3 3 2 4 2 3 5 1 4 2 3 2 - - 6 0 4 1 - - - - 5 0 - - - - 6 0 6 0 7 1 6 1 5 2 5 3 4 2 4 4 3 5 2 3 3 6 1 7 0 4 2 - - - - 5 1 - - - - 6 0 - - - -

Write down what you just did If N is input then consider x and y two variables as output For Red:

  • Start x from 0 to N by adding 1
  • Start y from N to 0 by subtracting 1 For Blue: If N is even:
  • Start x from 0 to N by adding 2
  • Start y from N+1 to 1 by subtracting 2 If N is odd:
  • Start x from 1 to N by adding 2
  • Start y from N to 1 by subtracting 2 For Green: If N is even:
  • Start x from 1 to N+1 by adding 2
  • Start y from N to 0 by subtracting 2 If N is odd:
  • Start x from 0 to N+1 by adding 2
  • Start y from N+1 to 0 by subtracting 2 Generalize your steps: o Fill the blocks with red when (x+y) is equal to N o Now see whether N is even or odd o If N is even:
  • When x is even, fill it with blue
  • Otherwise fill it with green o If N is odd:
  • When x is odd, fill it with blue
  • Otherwise fill it with green