




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various topics in c programming, including strings as character arrays, algorithms using arrays, multi-dimensional arrays, and comparing two arrays. It also discusses character arrays for reading and displaying names, displaying names using loops, and sorting algorithms such as bubble sort and binary search. Exercises for inputting names in reverse order and determining the length of character arrays.
Typology: Slides
1 / 36
This page cannot be seen from the preview
Don't miss anything!





























Lecture 12
Today’s Lecture Includes
Strings ( character arrays ) Algorithms using arrays Multi-dimensional arrays
In C we have Used
\n New Line
\t Tab Character
\0 Null Character
All C strings are terminated by Null character
Initializing an Array
Initializing array of integers
int c [ 10 ] = { 1,2,3,4,5,6,7,8,9,10 } ; int c [ ] = { 1,2,3,4,5,6,7,8,9,10 } ;
For character arrays char name [ 100 ] = { ‘a’,b’,’c’,’0’,’1’ } ; char name [ 100 ] = “abc01“ ; char name [ ] = “Hello World“ ; Docsity.com
Character Arrays
char name [ 100 ] ; cout << “ Please enter you name” ; cin >> name ; cout << name ;
Comparing Two arrays Array size should be equal int equal = 0 ; int num1 [ 100 ] , num2 [ 100 ] ; for ( i = 0 ; i < 100 ; i ++ ) { if ( num1 [ i ] != num2 [ i ] ) { equal = 1 ; break ; } } if ( equal ==1 ) cout << “ The arrays are not equal” ; else cout << “ The arrays are equal” ;
Condition :
Comparing Two Arrays
AZMAT HAMEED
Azmat Hameed
Sorting
Bubble Sort
Quick Sort
4
1
9
23
67
[0] [1] [2]
[16]
[99]
1
Brute-Force
Technique
Swapping Two
Numbers
int num [ ] ; int x ; x = num [ 0 ] ; num [ 0 ] = num [ 15 ] ; num [ 15 ] = x ;
Binary Search Algorithms
Divide and Conquer rule
5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4
1 2 3 4
Is divide and conquer the fastest way, all the time, of searching for a number in a list?
100
3
2
1 Linear Search?
Binary Search?
Suppose they are Ordered Suppose they are mixed-up
Functions and Arrays