Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 206 Lab Structured Programming in C

Similar presentations


Presentation on theme: "CSCE 206 Lab Structured Programming in C"— Presentation transcript:

1 CSCE 206 Lab Structured Programming in C
SPRING 2019 Lecture 6

2 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

3 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

4 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]);

5 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]); }

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

7 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

8 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

9 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


Download ppt "CSCE 206 Lab Structured Programming in C"

Similar presentations


Ads by Google