SlideShare a Scribd company logo
5
Most read
6
Most read
12
Most read
UNIT III
CHAPTER 1- ARRAYS
REFERENCE: PROGRAMMING IN C BY BALAGURUSWAMY
MRS. SOWMYA JYOTHI, SDMCBM, MANGALORE
Array : Array is a derived data type.
• When it is necessary to store more than one value
under a variable, user can make use of array.
•An array is a fixed-size sequence collection of
elements of the same data type.
•It is simply a grouping of like-data type.
Different types of arrays :
There are three types of arrays. They are,
1. One dimensional array.
2. Two dimensional array.
3. Multidimensional array.
One dimensional array :
•A list of items can be given one variable name using
only one subscript and such a variable is called
a one dimensional array.
Example : int number[5];
• Here in the example, 5 value of the variable
number can be kept under the single variable
number.
Declaration of one dimensional array : Like any other
variable, arrays must be declared before they are used.
•The general form of array declaration is,
• type variable_name[size];
The type specifies the type of elements that will be contained
in the array, such as int, float etc. The size indicates the
maximum number of element that can be stored inside the
array.
For example,
float height[50];
This declares the height to be an array containing 50 real
numbers.
Two dimensional array :
•When by using an array, user can store two value,
each for a row and a column under a variable, the
array is then called a two dimensional array.
Here, user can use infinite number of rows and
columns.
Two dimensional arrays are declared as follows,
• type array_name[row size][column size];
•Eg: int a[3][4];
Multidimensional array :
•C allows arrays of three or more dimensions. The exact limit
is determined by the compiler.
•The general form of a multidimensional array is,
• type arrayname[s1][s2]......[sn];
Where sn is the size of the dimension.
For example,
• int survey[3][5][12]
survey is a three dimensional array declared to contain 180
integer type elements.
Initialization of one dimensional array :
After an array is declared, its elements must be
initialized. An array can be initialized either of the
following stages,
1. At compile time.
2. At run time.
Compile time initialization :
User can initialize the elements of an array in the same
way as the ordinary variables when they are declared. This
is compile time initialization.
The general form is as follows,
• type arrayname[size]={list of values};
The values in the list are separated by commas.
For example,
• int number[3]={0,0,0};
This will declare the variable number as an array of size 3
and will assign 0 to each element.
Run time initialization :
• An array can be explicitly initialized at run time. This approach is
usually applied for initializing large arrays. For example,
for(i=0;i<100;i=i+1)
{
if (i<50)
sum[i]=0.0;
else
sum[i]=1.0;
}
The first 50 elements of the array sum are initialized to zero while the
remaining 50 elements are initialized to 1.0 at run time.
Initialization of two dimensional array :
Like the one dimensional arrays, two dimensional arrays may be
initialized by following their declaration with a list of initial
values enclosed in braces.
For example,
int table[2][3]={0,0,0,1,1,1};
This initializes the elements of the first row to 0 and the second
row to 1. This statement can also be written as,
• int table[2][3]={{0,0,0}, {1,1,1}};
• This can also be written as,
int table[2][3]= {
{0,0,0},
{1,1,1}
};
marks [0][0]
35.5
Marks [0][1]
40.5
Marks [0][2]
45.5
marks [1][0]
50.5
Marks [1][1]
55.5
Marks [1][2]
60.5
marks [2][0] Marks [2][1] Marks [2][2]
marks [3][0] Marks [3][1] Marks [3][2]
Elements of multi dimension arrays:
A 2 dimensional array marks [4][3] is shown below figure.
The first element is given by marks [0][0] contains 35.5 &
second element is marks [0][1] and contains 40.5 and so on.
min=a[1] i.e min=36
i=2
a[2]< min 55<36 NO
i=3
A[3]< min 23<36 YES
min=23 SWAP
i=4
A[4]<min 12<23 YES
min=12 SWAP
i=5
A[5]<min 95<12 NO
1 2 3 4 5
max=a[1] i.e max=36
i=2
a[2]> max 55>36 YES
max=a[2] max=55 SWAP
i=3
A[3]>max 23>55 NO
max=55 No change in max
i=4
A[4]>max 12>55 NO
i=5
A[5]>max 95>55 YES
Max=a[5] max=95 SWAP
i=6
A[6]>max 44>55 NO
• The Fibonacci Sequence is the series of numbers:
• 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
...
• Fibonacci Series is a pattern of numbers where each number is
the result of addition of the previous two consecutive numbers .
• First 2 numbers start with 0 and 1.
• The third numbers in the sequence is 0+1=1. The 4th number is
the addition of 2nd and 3rd number i.e. 1+1=2 and so on.
The next number is found by adding up the two numbers before
it:
• the 2 is found by adding the two numbers before it (1+1),
• the 3 is found by adding the two numbers before it (1+2),
• the 5 is (2+3),
• and so on!
f1 f2 f3
f1 f2
f3
{
f3 = f1 + f2;
printf(" %d", f3);
f1 = f2;
f2 = f3;
}
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
How to reverse a number mathematically.
• Step 1 — Isolate the last digit(rem) in number.
rem = number % 10
The modulo operator (%) returns the remainder of a divison.
• Step 2 — Append lastDigit(rem) to reverse.
reverse = (reverse * 10) + rem
• Step 3-Remove last digit from number.
number = number / 10.

More Related Content

PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PDF
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
PDF
Constants Variables Datatypes by Mrs. Sowmya Jyothi
PDF
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
PDF
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
PDF
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
PPTX
Overview of C Mrs Sowmya Jyothi
PPTX
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
Constants Variables Datatypes by Mrs. Sowmya Jyothi
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
Overview of C Mrs Sowmya Jyothi

What's hot (20)

PDF
Unit ii chapter 1 operator and expressions in c
PPTX
Functions in c
PDF
Unit II chapter 4 Loops in C
PPTX
Functions in c language
PPT
Decision Making and Branching in C
PPT
16717 functions in C++
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
PPT
Constants in C Programming
PPTX
Operators and expressions in c language
PPTX
C decision making and looping.
PPTX
Data Type in C Programming
PPT
Decision making and branching
PPT
Introduction to c programming
PPTX
Operators and expressions
PPT
Operators in C++
PPTX
Union in c language
PDF
Constructor and Destructor
PPTX
While , For , Do-While Loop
PPTX
C Programming: Control Structure
PPT
08 c++ Operator Overloading.ppt
Unit ii chapter 1 operator and expressions in c
Functions in c
Unit II chapter 4 Loops in C
Functions in c language
Decision Making and Branching in C
16717 functions in C++
 
C lecture 4 nested loops and jumping statements slideshare
Constants in C Programming
Operators and expressions in c language
C decision making and looping.
Data Type in C Programming
Decision making and branching
Introduction to c programming
Operators and expressions
Operators in C++
Union in c language
Constructor and Destructor
While , For , Do-While Loop
C Programming: Control Structure
08 c++ Operator Overloading.ppt
Ad

Similar to Arrays in c unit iii chapter 1 mrs.sowmya jyothi (20)

PDF
Array and its types and it's implemented programming Final.pdf
PDF
PPTX
Programming in c Arrays
PDF
Array
PPTX
Arrays 1D and 2D , and multi dimensional
PPTX
BHARGAVIARRAY.PPT.pptx
PDF
Array in C full basic explanation
PPTX
Arrays in C language
PPTX
Arrays basics
PPTX
Arrays in c
PPT
Array in c
PPTX
PPTX
ARRAYS.pptx
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
PPT
uderstanding arrays and how to declare arrays
PPTX
array ppt of c programing language for exam
PPTX
array-160309152651.pptx
PPT
presentation_arrays_1443553113_140676.ppt
Array and its types and it's implemented programming Final.pdf
Programming in c Arrays
Array
Arrays 1D and 2D , and multi dimensional
BHARGAVIARRAY.PPT.pptx
Array in C full basic explanation
Arrays in C language
Arrays basics
Arrays in c
Array in c
ARRAYS.pptx
Unit4pptx__2024_11_ 11_10_16_09.pptx
uderstanding arrays and how to declare arrays
array ppt of c programing language for exam
array-160309152651.pptx
presentation_arrays_1443553113_140676.ppt
Ad

More from Sowmya Jyothi (18)

PPTX
Stacks IN DATA STRUCTURES
PDF
Functions in c mrs.sowmya jyothi
PDF
Strings in c mrs.sowmya jyothi
PDF
Bca data structures linked list mrs.sowmya jyothi
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
PDF
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
PDF
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
PDF
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
PDF
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
PDF
Unit ii chapter 2 Decision making and Branching in C
PPT
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
PPT
Introduction to computers MRS. SOWMYA JYOTHI
PPT
Introduction to graphics
PDF
Inter Process Communication PPT
PDF
Internal representation of file chapter 4 Sowmya Jyothi
PDF
Buffer cache unix ppt Mrs.Sowmya Jyothi
PDF
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
PPT
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Stacks IN DATA STRUCTURES
Functions in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Unit ii chapter 2 Decision making and Branching in C
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to graphics
Inter Process Communication PPT
Internal representation of file chapter 4 Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Pre independence Education in Inndia.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
master seminar digital applications in india
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Classroom Observation Tools for Teachers
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Insiders guide to clinical Medicine.pdf
Renaissance Architecture: A Journey from Faith to Humanism
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Module 4: Burden of Disease Tutorial Slides S2 2025
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O7-L3 Supply Chain Operations - ICLT Program
Pre independence Education in Inndia.pdf
Basic Mud Logging Guide for educational purpose
Sports Quiz easy sports quiz sports quiz
Microbial disease of the cardiovascular and lymphatic systems
master seminar digital applications in india
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Institutional Correction lecture only . . .
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
VCE English Exam - Section C Student Revision Booklet
Classroom Observation Tools for Teachers

Arrays in c unit iii chapter 1 mrs.sowmya jyothi

  • 1. UNIT III CHAPTER 1- ARRAYS REFERENCE: PROGRAMMING IN C BY BALAGURUSWAMY MRS. SOWMYA JYOTHI, SDMCBM, MANGALORE
  • 2. Array : Array is a derived data type. • When it is necessary to store more than one value under a variable, user can make use of array. •An array is a fixed-size sequence collection of elements of the same data type. •It is simply a grouping of like-data type.
  • 3. Different types of arrays : There are three types of arrays. They are, 1. One dimensional array. 2. Two dimensional array. 3. Multidimensional array.
  • 4. One dimensional array : •A list of items can be given one variable name using only one subscript and such a variable is called a one dimensional array. Example : int number[5]; • Here in the example, 5 value of the variable number can be kept under the single variable number.
  • 5. Declaration of one dimensional array : Like any other variable, arrays must be declared before they are used. •The general form of array declaration is, • type variable_name[size]; The type specifies the type of elements that will be contained in the array, such as int, float etc. The size indicates the maximum number of element that can be stored inside the array. For example, float height[50]; This declares the height to be an array containing 50 real numbers.
  • 6. Two dimensional array : •When by using an array, user can store two value, each for a row and a column under a variable, the array is then called a two dimensional array. Here, user can use infinite number of rows and columns. Two dimensional arrays are declared as follows, • type array_name[row size][column size]; •Eg: int a[3][4];
  • 7. Multidimensional array : •C allows arrays of three or more dimensions. The exact limit is determined by the compiler. •The general form of a multidimensional array is, • type arrayname[s1][s2]......[sn]; Where sn is the size of the dimension. For example, • int survey[3][5][12] survey is a three dimensional array declared to contain 180 integer type elements.
  • 8. Initialization of one dimensional array : After an array is declared, its elements must be initialized. An array can be initialized either of the following stages, 1. At compile time. 2. At run time.
  • 9. Compile time initialization : User can initialize the elements of an array in the same way as the ordinary variables when they are declared. This is compile time initialization. The general form is as follows, • type arrayname[size]={list of values}; The values in the list are separated by commas. For example, • int number[3]={0,0,0}; This will declare the variable number as an array of size 3 and will assign 0 to each element.
  • 10. Run time initialization : • An array can be explicitly initialized at run time. This approach is usually applied for initializing large arrays. For example, for(i=0;i<100;i=i+1) { if (i<50) sum[i]=0.0; else sum[i]=1.0; } The first 50 elements of the array sum are initialized to zero while the remaining 50 elements are initialized to 1.0 at run time.
  • 11. Initialization of two dimensional array : Like the one dimensional arrays, two dimensional arrays may be initialized by following their declaration with a list of initial values enclosed in braces. For example, int table[2][3]={0,0,0,1,1,1}; This initializes the elements of the first row to 0 and the second row to 1. This statement can also be written as, • int table[2][3]={{0,0,0}, {1,1,1}}; • This can also be written as, int table[2][3]= { {0,0,0}, {1,1,1} };
  • 12. marks [0][0] 35.5 Marks [0][1] 40.5 Marks [0][2] 45.5 marks [1][0] 50.5 Marks [1][1] 55.5 Marks [1][2] 60.5 marks [2][0] Marks [2][1] Marks [2][2] marks [3][0] Marks [3][1] Marks [3][2] Elements of multi dimension arrays: A 2 dimensional array marks [4][3] is shown below figure. The first element is given by marks [0][0] contains 35.5 & second element is marks [0][1] and contains 40.5 and so on.
  • 13. min=a[1] i.e min=36 i=2 a[2]< min 55<36 NO i=3 A[3]< min 23<36 YES min=23 SWAP i=4 A[4]<min 12<23 YES min=12 SWAP i=5 A[5]<min 95<12 NO 1 2 3 4 5
  • 14. max=a[1] i.e max=36 i=2 a[2]> max 55>36 YES max=a[2] max=55 SWAP i=3 A[3]>max 23>55 NO max=55 No change in max i=4 A[4]>max 12>55 NO i=5 A[5]>max 95>55 YES Max=a[5] max=95 SWAP i=6 A[6]>max 44>55 NO
  • 15. • The Fibonacci Sequence is the series of numbers: • 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... ... • Fibonacci Series is a pattern of numbers where each number is the result of addition of the previous two consecutive numbers . • First 2 numbers start with 0 and 1. • The third numbers in the sequence is 0+1=1. The 4th number is the addition of 2nd and 3rd number i.e. 1+1=2 and so on. The next number is found by adding up the two numbers before it: • the 2 is found by adding the two numbers before it (1+1), • the 3 is found by adding the two numbers before it (1+2), • the 5 is (2+3), • and so on!
  • 16. f1 f2 f3 f1 f2 f3 { f3 = f1 + f2; printf(" %d", f3); f1 = f2; f2 = f3; }
  • 18. How to reverse a number mathematically. • Step 1 — Isolate the last digit(rem) in number. rem = number % 10 The modulo operator (%) returns the remainder of a divison. • Step 2 — Append lastDigit(rem) to reverse. reverse = (reverse * 10) + rem • Step 3-Remove last digit from number. number = number / 10.