CSCE 206 Lab Structured Programming in C

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Week 8 Arrays Part 2 String & Pointer
Lab 8 User Defined Function.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Multiple-Subscripted Array
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 9: Pass-by-Value.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Arrays and Strings Gabriel Hugh Elkaim Spring 2013.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Lecture 15: Projects Using Similar Data. What is an Array? An array is a data structure consisting of related data items of the same type. Stored in a.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CSCI 161 Lecture 14 Martin van Bommel. New Structure Recall “average.cpp” program –Read in a list of numbers –Count them and sum them up –Calculate the.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
CSC Programming for Science Lecture 26: Arrays.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
CSE 251 Dr. Charles B. Owen Programming in C1 Pointers and Reference parameters.
Introduction to programming in java Lecture 21 Arrays – Part 1.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Arrays in C. What is Array? The variables we have used so far can store a single value. Array is a new type of variable capable of storing many values.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Lecture 5 array declaration and instantiation array reference
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Introduction to Programming Using C
CSE 220 – C Programming Pointers.
Array An “average.cpp” program
Lecture2.
Lecture 6 C++ Programming
C++ Arrays.
CSC 253 Lecture 8.
Lecture 9 : Array Acknowledgment : Lecture notes from Ohio Supercomputing Center.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CSC 253 Lecture 8.
One-Dimensional Array Introduction Lesson xx
CSCE 206 Lab Structured Programming in C
Chapter 8 Arrays Objectives
CS-161 Computer Programming Lecture 14: Arrays I
Chapter 6 Arrays Fall 2012 CS2302: Programming Principles.
Lecture 18 Arrays and Pointer Arithmetic
Introduction To Programming Information Technology , 1’st Semester
CSCE 206 Lab Structured Programming in C
Topics discussed in this section:
MSIS 655 Advanced Business Applications Programming
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CISC181 Introduction to Computer Science Dr
Arrays I Handling lists of data.
Functions.
INC 161 , CPE 100 Computer Programming
Chapter 8 Arrays Objectives
ECE Application Programming
CS149D Elements of Computer Science
Suggested self-checks: Section 7.11 #1-11
C Programming Lecture-8 Pointers and Memory Management
Arrays Arrays A few types Structures of related data items
Loops.
C Programming Pointers
Java: Variables, Input and Arrays
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
Presentation transcript:

CSCE 206 Lab Structured Programming in C SPRING 2019 Lecture 6

Arrays Store many items in the same variable Fixed size: specified at declaration 1 2 3 5 8 13 21 34 55 Value: Position: 9

Arrays Store many items in the same variable Fixed size: specified at declaration 1 2 3 5 8 13 21 34 55 Segmentation fault Value: Position: 10

Array declaration & use int fib[10]; fib[0] = fib[1] = 1; for (i = 2; i < 10; i++) { fib[i] = fib[i-1] + fib[i-2]; } for (i = 0; i < 10; i++) { printf("%d\n", fib[i]);

Array in functions (pass by reference) int fib[10]; fib[0] = fib[1] = 1; fibonacci(fib); for (i = 0; i < 10; i++) { printf("%d\n", fib[i]); }

Array in functions (pass by reference) void fibonacci(int fib){ for (i = 2; i < 10; i++) { fib[i] = fib[i-1] + fib[i-2]; }

Practice Problem-1 Write a program that takes from the input: One integer “size” that represents the size of the array “size” number of integers (int array) And prints the sum and the product of all the numbers From the main, call: One function to get the input from the array (not the size) One function to calculate the product One function to calculate the sum

Practice Problem-2 Write a program that takes from the input: One integer “size” that represents the size of the array “size” number of integers (int array) And prints the series of numbers inputted, each incremented by 1 From the main, call: One function to get the input from the array (not the size) One function to modify the original array One function to print the array

Practice Problem-3 Write a program that takes from the input: One integer “size” that represents the size of the array “size” number of characters (char array) And prints the characters in reversed order From the main, call: One function to get the input from the array (not the size) One function to modify the original array One function to print the array