0% found this document useful (0 votes)
63 views

Our Presentation On Chapter 6 of C: Group Members: Ockouri Barnes Piccard Harris Maliek Allwood Malikai Allwood

Here are the outputs of the modified program with sorting and searching options: Please enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Menu: 1. To sort 2. To search Please select an option (1 or 2): 1 The numbers in ascending order are: 1 2 3 4 5 6 7 8 9 10 Menu: 1. To sort 2. To search Please select an option (1 or 2): 2 Please enter the number to search for: 5 Number found at position 4 Menu: 1. To sort 2. To search Please select an option (1 or 2):

Uploaded by

Ockouri Barnes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Our Presentation On Chapter 6 of C: Group Members: Ockouri Barnes Piccard Harris Maliek Allwood Malikai Allwood

Here are the outputs of the modified program with sorting and searching options: Please enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Menu: 1. To sort 2. To search Please select an option (1 or 2): 1 The numbers in ascending order are: 1 2 3 4 5 6 7 8 9 10 Menu: 1. To sort 2. To search Please select an option (1 or 2): 2 Please enter the number to search for: 5 Number found at position 4 Menu: 1. To sort 2. To search Please select an option (1 or 2):

Uploaded by

Ockouri Barnes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

OUR PRESENTATION

ON CHAPTER 6 OF C
GROUP MEMBERS: OCKOURI BARNES
PICCARD HARRIS
MALIEK ALLWOOD
MALIKAI ALLWOOD
WHAT IS AN ARRAY AND ITS ATTRIBUTES ?

ARRAY ATTRIBUTES
 Variables in an array share the same name.
 An array is a series of memory locations
 Variables in an array share the same data type.
or boxes each of which holds a single
item/element of data but with each box   Individual variables in an array are called
sharing the same name. All data in elements.

an array must be of the same data type.  Elements in an array are accessed with an
index number.
IMPORTANT THINGS TO REMEMBER ABOUT
ARRAYS
 To refer to a particular location or element in the array we specify the name of the array and
the position number of the particular element in the array.
 The first element in every array is the zeroth element.
 Any one of these elements may be referred to by giving the name of the array followed by
the position number of the particular element in square brackets ([ ]).
 The position number contained within square brackets is more formally called a  subscript
(or index).
 Arrays are “static” entities in that they remain the same size throughout program execution.
TYPES OF ARRAYS

 One Dimensional Arrays


 Two Dimensional Arrays
 Multi-Dimensional Arrays
ONE DIMENSIONAL ARRAYS

 Accessing its elements involves a single subscript which can either represent a row or column
index. As an example consider the C declaration int anArrayName[10]; which declares a one
dimensional array of ten integers. Here the array can store ten elements of type int .
 You can quickly initialize your arrays with a single default value as demonstrated in the
following array declaration.
            int iArray[5] = {0};
 Assigning the single numeric value of 0 in an array declaration will by default assign all array
elements the value of 0.
INITIALIZATION OF ELEMENTS IN AN ARRAY [C
CODE]
initializing an array */
 #include <stdio.h>
int main( void )
{
int n[ 10 ]; /* n is an array of 10 integers */
int i; /* counter */
/* initialize elements of array n to 0 */
      for ( i = 0; i < 10; i++ ) {
      n[ i ] = 0; /* set element at location i to 0 */
      } /* end for */
printf( "%s%13s\n", "Element", "Value" ); 
* /output contents of array n in tabular format */
    for ( i = 0; i < 10; i++ ) {
    printf( "%7d%13d\n", i, n[ i ] );
} /* end for */
return 0; /* indicates successful termination */
} /* end main */
C OUTPUT OF ARRAY WHICH INITIALIZED ITS
ELEMENTS TO ZERO
CHRACTER ARRAYS

Character arrays should be initialized before using them. Elements in a character array hold
characters plus a special null termination character which is represented by the character
constant '/0'. Character arrays can be initialized in a number of ways. For instance,
the following code initializes an array with a predetermined character sequence.
        char cName[ ] = { 'O', 'l', 'i', 'v', 'i', 'a', '\0' };
The next statements shows the declaration:
        char cName[ ] = "Olivia";
CHARACTER ARRAYS CONT'D

 When creating character arrays be sure to allocate Functions such as printf and scanf
enough room to store the largest character
sequence assignable. Also remember to allow does not check how large the
enough room in the character array to store the null character array is. The characters
character (‘\0’).
of the string are printed until a
 A character array representing a string can  output
terminating null character is
with printf and the %s conversion specifier. The
array string2 is printed with the statement  encountered.
        printf( "%s\n", string2 );
STRING ARRAYS

EXPLANATION OF STRING ARRAYS MANIPULATION OF STRING ARRAYS

 In a sense string arrays are an arrays of characters. You can create an array of strings 1) The strcpy() function copies the contents of one string into another string. The
with a one dimensional pointer array and assign string literals to it or you can create strcpy() function takes two strings as arguments. The first argument is the
a two dimensional pointer array allowing C to reserve enough memory for each string to be copied into and the second argument is the string that will be
character array. copied from.

 When printed to standard output, strings are not surrounded by quotes 2) A useful string library function is the strcat() function which concatenates or
automatically. This can be accomplished by using special quote characters in a glues one string to another.
printf() function. You can display quotes in standard output using a conversion 3) The strcmp() function is a very interesting and useful function that is primarily
specifier, more specifically the \" conversion specifier as the next print statement used to compare two strings for equality.
demonstrates:
4) The strstr() function takes two strings as arguments and searches the first string
      printf("\nString 1 is \"%s\"\n", str1); for an occurrence of the second string.
SORTING MECHANISM AND TYPES

DEFINTION TYPES
 The process of Sorting can be explained as  Selection Sort

a technique of rearranging the elements in  Bubble Sort

any particular order which can be set ready  Recursive Bubble Sort

for further processing by  Insertion Sort

the program logic.  Recursive Insertion Sort


 Merge Sort
 Iterative Merge Sort
 Quick Sort
SEARCHING MECHANISM AND TYPES

DEFINITION TYPES
 Searching is the process of finding a   Linear search
given value position in a list of values. It  Sequential search 
decides whether a search key is present
 Binary search
in the data or not. It is the algorithmic
process of finding a particular item in a
collection of items.
DIFFERENCE BETWEEN SORTING & SEARCHING

 The Search mechanisms are designed to retrieve an element from any data structure
where it is used. A Sorting mechanism is used to arranging the data of list or array into
some specific order.
C QUESTIONS FROM C ABSOLUTE
BEGINNERS
 C CODES WITH OUTPUTS
 FOCUS ONE DIMENSIONAL ARRAYS
QUESTION 1:
BUILD A PROGRAM THAT USES A SINGLE-DIMENSION ARRAY TO STORE 10 NUMBERS INPUT BY A USER. AFTER
INPUTTING THE NUMBERS, THE USER SHOULD SEE A MENU WITH TWO OPTIONS TO SORT AND PRINT THE 10
NUMBERS IN ASCENDING OR DESCENDING ORDER.
Outputs:
QUESTION 2: 
  
CREATE A STUDENT GPA AVERAGE CALCULATOR. THE PROGRAM SHOULD PROMPT THE USER TO ENTER UP TO 30 GPAS, WHICH ARE STORED IN A SINGLE-DIMENSION ARRAY. EACH TIME HE OR SHE ENTERS A GPA, THE USER SHOULD HAVE THE OPTION TO CALCULATE THE CURRENT GPA AVERAGE OR
ENTER ANOTHER GPA. SAMPLE DATA FOR THIS PROGRAM IS SHOWN BELOW. 
GPA: 3.5 
GPA: 2.8 
GPA: 3.0 
GPA: 2.5 
GPA: 4.0 
GPA: 3.7 
GPA AVERAGE: 3.25 
HINT: BE CAREFUL TO NOT CALCULATE EMPTY ARRAY ELEMENTS INTO 
YOUR STUDENT GPA AVERAGE. 
Outputs:

Error handling:
C QUESTIONS FROM C HOW TO
PROGRAM
 C CODES WITH OUTPUTS
 SEARCH MECHANISM
 SORT MECHANSIM
Copy the program on page 217 and modify it so that a menu is added to give the user the following options.
* 1. To sort
* 2. To Search
* Please select an option (1 or 2):
Then use the search program on page 139 in the C for Absolute beginners as a guide to implement the search in your program
Outputs:

You might also like