CS1010 Discussion Group 11 Week 7 – Two dimensional arrays.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Chapter 9: Arrays and Strings
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
A First Book of ANSI C Fourth Edition
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
C Lecture Notes 1 Arrays Lecture 6. C Lecture Notes 2 6.1Introduction Arrays –Structures of related data items –Static entity – same size throughout program.
Introduction to Programming
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
UNIT 10 Multidimensional Arrays.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Objectives You should be able to describe: One-Dimensional Arrays
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
A bit of C programming Lecture 3 Uli Raich.
ECE Application Programming
Computer Programming BCT 1113
© 2016 Pearson Education, Ltd. All rights reserved.
Documentation Need to have documentation in all programs
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
CS1010 Discussion Group 11 Week 11 – Recursion recursion recursion….
CS1010 Discussion Group 11 Week 9 – Pointers.
ICS103 Programming in C Lecture 3: Introduction to C (2)
CS1010 Discussion Group 11 Week 6 – One dimensional arrays.
Other Kinds of Arrays Chapter 11
A First Book of ANSI C Fourth Edition
Arrays in C.
Chapter 2 part #3 C++ Input / Output
Advanced Programming Behnam Hatami Fall 2017.
Some Basics for Problem Analysis and Solutions
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
CS 2308 Final Exam Review.
CS 2308 Exam I Review.
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
CS 2308 Exam I Review.
C Arrays.
CNG 140 C Programming (Lecture set 8)
Arrays Outline Introduction Arrays Declaring Arrays
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
CS 1428 Final Exam Review.
IPC144 Introduction to Programming Using C Week 8 – Lesson 1
Chapter 3: Input/Output
Your questions from last session
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
CS 1428 Final Exam Review.
Functions continued.
1-6 Midterm Review.
EECE.2160 ECE Application Programming
Chapter 2 part #3 C++ Input / Output
Arrays.
Chapter 1 c++ structure C++ Input / Output
EECE.2160 ECE Application Programming
EE 312 Exam I Review.
Presentation transcript:

CS1010 Discussion Group 11 Week 7 – Two dimensional arrays

Slides are at http://www.comp.nus.edu.sg/~yanhwa/ HELLO! Slides are at http://www.comp.nus.edu.sg/~yanhwa/

Practical Exam Tips Know how to use %c in printf, using %d will print the ascii value of a number (the number that you get when you convert a character to an integer) Use pow() for power, but remember that if there is a warning that complains “pow is undefined” then you did not import math.h or you did not compile with –lm flag Be familiar with error messages: floating-point exception is (usually) when you try to divide a float with zero.

To use “n” or avoid “n”? Just use num Practical Exam Tips A function prototype or function interface is a declaration of a function that specifies the function's name and type signature (data types of parameters) and return type. Thus if you face warnings regarding prototypes, check all these. To use “n” or avoid “n”? Just use num Preconditions. Indentation. Comments. Description. Your program must be able to compile! -5 for compiler warning with –Wall. Only declare variables at the start of a function

Take note of overflow (which variables need to be long long int type?) Practical Exam Tips Seesoo has to be done with two nested loops because the first loop is to calculate the “seesoo”. Have to repeat this calculation while seesoo > 9. Easiest to do teetoo if do it step by step. Remove the last group of three first, which is making life difficult. After that, it is easy to deal with groups of 4 (with one number that you ignore) Take note of overflow (which variables need to be long long int type?) Invalid operands to binary % (have ‘long long int’ and ‘double’) Only 10%.... 10%0 = infinity…

Practical Exam Tips Use two SSH Secure Shell Clients, one to program, one to compile. Don’t break the “flow” of programming Press “up arrow” to traverse through the command history Remember, you can printf everywhere to debug your program. Figure out which part causes the error/bug by following the “flow” of the program and mentally tracing it out, with the help of the printf statements. printf(“digit: %d”, digit); Comment out parts of program if unable to compile or there are warning messages and see if there are any change. Syntax errors vs run-time errors Check output whether it conforms with requirements!!! Don’t give up, we try to award as many marks as possible especially if there is only minor logic errors :’) Be familiar with char and int conversion

int arr[3] = {0} all elements initialized to zero Practical Exam Tips Debug infinite loops using printf. Find the flow of the program, see what will be printed. Set variable counter = 0. break if counter == some number. Input/output stream redirection ./a.out < seesoo1.in ./a.out < seesoo1.in > ans.out saves the output diff ans.out seesoo1.out compares correct output with your output int arr[3] = {0} all elements initialized to zero Int arr[3] = {1} only first element initialized to 1

Be familiar with char and int. PE Tips Be familiar with char and int. printf("%c\n", (char) ((int) 'C' + beeboo_val%10)); char[] string[i] = number + '0'; int value = c - '0';

PE Tips

Have you seen the past year papers? (and answers?) Midterms Midterms on Friday! Have you seen the past year papers? (and answers?)

Lab 4 Exercise 2 worksheet

THE ARRAY data structure Lecture Summary A function header with array parameter, int sum(int a[ ], int size) Why is it not necessary to indicate size of array in the brackets? Each integer is 4 bytes big. 4 bytes = 4x8 bits = 32 bits!

THE ARRAY data structure Lecture Summary How to declare 2D array? // the first dimension can be unspecified int b[][5] = { {4, 2, 1, 0, 0}, {8, 3, 3, 1, 6}, {0, 0, 0, 0, 0} }; // initializer with implicit zero values int d[3][5] = { {4, 2, 1}, {8, 3, 3, 1, 6} }; Why must we specify the 2nd dimension?

2D arrays where memory is linear and row-major order Lecture Summary 2D arrays where memory is linear and row-major order Address of A[i][j] = base_address + size * (i * num_cols + j)

Linear Search (Just searching…) O(n) Lecture Summary Linear Search (Just searching…) O(n) Binary Search (Searching a phone book) Bubble Sort (Bubbling the max to the back) Selection Sort (Selecting the minimum to be placed at the front) Insertion Sort (Putting each element at its correct position backwards, like sorting a hand of cards) http://visualgo.net

Tutorial 1b Yes, all of the formats work. For numerical inputs, scanf() skips whitespaces to read the next value.

Tutorial 2 \n \n The newline character will be read into the element values[1][0]. Could correct it by using a dummy character to hold the newline. Alternatively, the program could be re-written by reading a string for each row of characters. (String will be covered in week 9 lecture.)

Tutorial 3 4 10 20 2 3 4 5 4 5 7 8 6

Product of two matrices

Diagonal and triangular Send me your programs!

Find the most frequent value in a 2D array? Extra Find the most frequent value in a 2D array? 1. If you know the max value of the array 2. if you don’t know the max value http://www.geeksforgeeks.org/find-the- maximum-repeating-number-in-ok-time/

NIRC check digit, weights and alphabet letter Extra NIRC check digit, weights and alphabet letter http://coding-and-crypto.tripod.com/01NRIC.htm

Add to your cheatsheet!

Midterms PYP