Lecture 12: Multi-Dimensional Arrays and Sorting in C Programming for Engineers, Study notes of Engineering

The concept of multi-dimensional arrays in c programming, with a focus on two-dimensional arrays. It also introduces the sorting algorithm, specifically bubble sort, and provides code examples. Students will learn how to declare and access multi-dimensional arrays, understand the importance of sorting, and write code to sort an array using bubble sort.

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-xjp
koofers-user-xjp 🇺🇸

8 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A
Introduction to C Programming for Engineers
Lecture #12
Jeffrey Miller, Ph.D.
pf3
pf4
pf5
pf8

Partial preview of the text

Download Lecture 12: Multi-Dimensional Arrays and Sorting in C Programming for Engineers and more Study notes Engineering in PDF only on Docsity!

CSE294A

Introduction to C Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

Multi-Dimensional Arrays

An array is a group of memory locations related by the factthat they all have the same name and the same type

The arrays we discussed last lecture were one-dimensionalarrays, meaning that they were addressed by a single index

int my_array[10];

Multi-dimensional arrays are addressed by more than oneindex

A two-dimensional array is actually an array of arrays, althoughpeople like to think of them as “tables” or “matrices”

int my_2d_array[10][20];

Sorting

A very common algorithm used in programming issorting

Problem

Assume you have an array of integers and the numberof integers in the array, put the integers in the samearray in ascending (or descending) order

Start

End

Bubble Sort

One approach is to iterate through the entire arrayand put the smallest number in the right place

After the smallest number is at index 0, find thesecond smallest number and put it at index 1

Continue until all of the numbers are in the rightplace

Now try to write the code to do this…beforelooking at the next slide

Program

Write a program that prompts the user to enter a numberbetween 2 and 5000. Randomly generate that manynumbers, print out the original set of values, then sort thevalue and print out the sorted set of values.

Homework

Homework #6 is posted!