SlideShare a Scribd company logo
Arrays
Chapter contains
• Single dimensional array [ ]
• Multiple dimensional array [ ][ ], [ ][ ][ ]
• Pointer
• Symbol of array : [ ]
• Array enable a variable to store more than 1 data
• Data can be stored as integer, character, float
• Normally we stored value as variable a,b,c..
• How about if we have 1000 variables ?
• Array- A set of data with similar properties and which
are stored in consecutive memory location under
common variable name
WHAT IS ARRAY?
Subscript
• Array also known as subscripted variable
• General form
• Name[i], number [i][j]
• i and j is subscript
• Following rules should be followed while using subscript
• A subscript may be a valid integer
• The value of subscript is zero or positive
• A subscript must not be subscripted variable
• If a variable is used to represent an array it should not be used as
ordinary variable
Type of array
• Array in integer: int a[10] array ‘a’ with capacity
of 10, it able to store 10 sets of integer value.
• Array in float: float sum[5]  array ‘sum’ with
capacity of 5, it able to store 5 sets of float value.
• Array in char: char no[4]  array ‘no’ with capacity
of 4, it able to store 4 set of alphabet.
Function of array: to store huge data
sets in a systematic way
HOW TO DECLARE ARRAY??
Integer and character array
One dimensional array
• int x[10]
• Array is declared as ordinary variable, but size of the
array must be specified within the square bracket
Output
x[0] x[1] x[2] x[3] x[4]
HOW TO DECLARE ARRAY?
Run time initialization
• Array can be initialize during execution of the
program in 2 different ways
• By using assignment statement
(+=, -=, *=, /=,%=)
• By using input statement
Output
This coding shows how we allocate
/display the one dimensional array
Output
This coding shows how we allocate /display the one dimensional array
By using array function, develop a program to
store 5 different value in X array, next calculate
the average of total obtained values.
Array-part1
Exercise
Write a program to store 5 digits below and perform
different arithmetic operation on these digits using
single array function:
First operation: 4/5
Second operation: 4+11/12
Third operation: 9%11
4 5 11 12 9
• #include<stdio.h>
• int main()
• {
• int mark[5] = {4,5,11,12,9};
• printf("first operation: %d n",mark[0]/mark[1]);
• printf("second operation: %dn",mark[0]+mark[2]/mark[3]);
• printf("third operation: %d n",mark[4]%mark[2]);
• return 0;
•
• }
TRY THIS?
DEVELOP A PROGRAM TO SHOW STUDENT’S
TEST MARK WHEN THEIR MATRIC NO IS
TYPED USING ARRAY FUCNTION. THE
STUDENT AND THEIR MARKS ARE AS BELOW:
Array MATRIC NO TEST MARK
[0] 111 10
[1] 222 20
[2] 333 30
[3] 444 40
[4] 555 50
Array-part1
#include<stdio.h>
int main()
{
int mat[ ]={111,222,333,444,555};
int arr[ ] = {10,20,30,40,50};
int i;
printf(“enter your matric number: “,i);
scanf(“%d”, &i);
mat[i]=arr[i];
printf("matrix number of %d is %d n", mat[i], arr[i]);
return 0;
}
Multidimensional array
• In multidimensional array the number of subscript is more than 1
• int a[i][j][k]
• The declaration is similar to one dimensional array.
• int x[3][2]
• x[0][0] x[0][1]
• x[1][0] x[1][1]
• x[2][0] x[2][1]
• The size of this array is 6
Set [0]
x[0][0] x[0][1]
x[1][0] x[1][1]
x[2][0] x[2][1]
The size of this array is 12
x[0][0] x[0][1]
x[1][0] x[1][1]
x[2][0] x[2][1]
The size of this array is
6
row
Example for 2D
int x[3][2]
Example for 3D
int x[2][3][2]
column row column
set
Array-part1
Array-part1
Output
2D array
This coding shows how we allocate /display the
array in 5 row and 2 column
2D array
Output
This coding shows relation operation in 2D array.
5 6 7
10 20 30
0
1
0 1 2
Array a
5+1 6+2 7+3
10+3 20+2 30+1
0
1
0 1 2
Array sum
1 2 3
3 2 1
0
1
0 1 2
Array b
Allocate the 2D arrays
Do the (+) operation
Example:
a[0][0]+ b[0][0]=5+1=6
a[0][1]+b[0][1]=6+2=8
… until a[1][1]+b[1][1]
1 2
3 4
5 6
7 8
9 10
11 12
0
1
2
0
1
2
0 1 0 1
Set (0) Set (1)
The
arrangement of
the array
Output
For 3D array you can write like this or go to the next page
3D array
For 3D array you can write like this or like previous
page
3D array
Example
• Write a program to find the transpose matrix of order m x n;
• Write a program to find y= 𝑖=1
𝑛
𝑖2 and sum of y
using an array. n is defined by user
Example 1
Answer
Example 2
Write a program to find y= 𝑖=1
𝑛
𝑥2 and
average of y using an array. X and n is
defined by user
#include <stdio.h>
#include <math.h>
int main()
{ int i,n, sums=0,array[i], average;
printf("insert n: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{ scanf("%d",&array[i]);
sums+=array[i]*array[i];
average=sums/n; }
printf("sums is %d",sums);
printf("n average= %d", average);
return 0;
}
 If have this mathematical problem
𝒊=𝟏
𝒏
𝒙 , the coding must be solve
using array
 Replace x  with array x [i] @
array[i]
 Declare sums=0 at int/float. Follow
how many sum in the question. Like
this example only have 1 sum
operation.
 The coding also have to use “for”
function
Insert n 3
Max array are x[3]  you have to input 3 number
Exp:
array[0] insert 2
array[1] insert 4
array[2] insert 3
Output:
i array[i] Sum+=array[i]*array[i] Average=sum/n
0 2 0+(2*2)=4 4/1=4
1 4 4+(4*4)=20 16/2=8
2 3 20+(3*3)=29 29/3=9
array[i]={2,3,4}
Write a program to calculate the
value of y, where xi is series of
value in data set, n is number of
values in data set and µ is mean of
all values. The values of xi, and n
are obtained from user input
#include<studio.h>
#includ<math.h>
int main()
{
int n,i, x[10],
float y, sumx sumx2, sumx3,sumx4, mean;
scanf("%d",&n);
for(i=0;i<n;i++);
{
scanf("%d",&x[i]);
sumx+=x[i]*x[i]
sumx2+=sqt(x[i]);
sumx3+=x[i];
mean=sumx3/n;
sumx4+=pow(x[i],3.0)*meanmean;
}
y=sumx/(n*sumx2)-sumx4;
prinf("y= %d",y);
return 0;
}
Example 3
Answer: Correct the error in the program and
try to run it.
y= 𝑖
𝑛
𝑥𝑖
2
𝑛 𝑖
𝑛 𝑥𝑖
1/2 − 𝑖
𝑛
𝑥𝑖
3 𝜇2
When, 𝜇 = 𝑖
𝑛
𝑥𝑖
𝑛
Write a program to calculate the value of y, where xi is series of value in
data set, n is number of values in data set and µ is mean of all values. The
values of xi, and n are obtained from user input
Exercise
y= 𝑖
𝑛
𝑥𝑖𝜇
𝑛3 − 𝑖
𝑛
𝑥𝑖

More Related Content

Similar to Array-part1 (20)

PPTX
Array in C
adityas29
 
PPTX
Arrays in C language
Shubham Sharma
 
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
PPT
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
PPTX
Arrays basics
sudhirvegad
 
PDF
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
PPTX
array-160309152651.pptx
karunapatel13
 
PPTX
Array ppt you can learn in very few slides.
dwivedyp
 
PPT
Arrays in c
vampugani
 
PPTX
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
PPTX
Array 2 hina
heena94
 
PPTX
Arrays & Strings
Munazza-Mah-Jabeen
 
PDF
Array in C.pdf
georgejustymirobi1
 
PDF
Array.pdf
mounikanarra3
 
PPTX
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
PPTX
Array.pptx
Govindraj Chittapur
 
PPT
Array
Tejas Patel
 
PPTX
Array.pptx Array.pptxArray.pptx Array.pptxArray.pptxArray.pptx
yatakumar84
 
PPTX
Arrays
RaziyasultanaShaik
 
PPTX
3.ArraysandPointers.pptx
FolkAdonis
 
Array in C
adityas29
 
Arrays in C language
Shubham Sharma
 
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
Arrays basics
sudhirvegad
 
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
array-160309152651.pptx
karunapatel13
 
Array ppt you can learn in very few slides.
dwivedyp
 
Arrays in c
vampugani
 
BHARGAVIARRAY.PPT.pptx
Sasideepa
 
Array 2 hina
heena94
 
Arrays & Strings
Munazza-Mah-Jabeen
 
Array in C.pdf
georgejustymirobi1
 
Array.pdf
mounikanarra3
 
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Array.pptx Array.pptxArray.pptx Array.pptxArray.pptxArray.pptx
yatakumar84
 
3.ArraysandPointers.pptx
FolkAdonis
 

Recently uploaded (20)

PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Ad

Array-part1

  • 2. Chapter contains • Single dimensional array [ ] • Multiple dimensional array [ ][ ], [ ][ ][ ] • Pointer
  • 3. • Symbol of array : [ ] • Array enable a variable to store more than 1 data • Data can be stored as integer, character, float • Normally we stored value as variable a,b,c.. • How about if we have 1000 variables ? • Array- A set of data with similar properties and which are stored in consecutive memory location under common variable name WHAT IS ARRAY?
  • 4. Subscript • Array also known as subscripted variable • General form • Name[i], number [i][j] • i and j is subscript • Following rules should be followed while using subscript • A subscript may be a valid integer • The value of subscript is zero or positive • A subscript must not be subscripted variable • If a variable is used to represent an array it should not be used as ordinary variable
  • 5. Type of array • Array in integer: int a[10] array ‘a’ with capacity of 10, it able to store 10 sets of integer value. • Array in float: float sum[5]  array ‘sum’ with capacity of 5, it able to store 5 sets of float value. • Array in char: char no[4]  array ‘no’ with capacity of 4, it able to store 4 set of alphabet.
  • 6. Function of array: to store huge data sets in a systematic way
  • 7. HOW TO DECLARE ARRAY??
  • 9. One dimensional array • int x[10] • Array is declared as ordinary variable, but size of the array must be specified within the square bracket Output x[0] x[1] x[2] x[3] x[4]
  • 10. HOW TO DECLARE ARRAY?
  • 11. Run time initialization • Array can be initialize during execution of the program in 2 different ways • By using assignment statement (+=, -=, *=, /=,%=) • By using input statement Output This coding shows how we allocate /display the one dimensional array
  • 12. Output This coding shows how we allocate /display the one dimensional array
  • 13. By using array function, develop a program to store 5 different value in X array, next calculate the average of total obtained values.
  • 15. Exercise Write a program to store 5 digits below and perform different arithmetic operation on these digits using single array function: First operation: 4/5 Second operation: 4+11/12 Third operation: 9%11 4 5 11 12 9
  • 16. • #include<stdio.h> • int main() • { • int mark[5] = {4,5,11,12,9}; • printf("first operation: %d n",mark[0]/mark[1]); • printf("second operation: %dn",mark[0]+mark[2]/mark[3]); • printf("third operation: %d n",mark[4]%mark[2]); • return 0; • • }
  • 17. TRY THIS? DEVELOP A PROGRAM TO SHOW STUDENT’S TEST MARK WHEN THEIR MATRIC NO IS TYPED USING ARRAY FUCNTION. THE STUDENT AND THEIR MARKS ARE AS BELOW: Array MATRIC NO TEST MARK [0] 111 10 [1] 222 20 [2] 333 30 [3] 444 40 [4] 555 50
  • 19. #include<stdio.h> int main() { int mat[ ]={111,222,333,444,555}; int arr[ ] = {10,20,30,40,50}; int i; printf(“enter your matric number: “,i); scanf(“%d”, &i); mat[i]=arr[i]; printf("matrix number of %d is %d n", mat[i], arr[i]); return 0; }
  • 20. Multidimensional array • In multidimensional array the number of subscript is more than 1 • int a[i][j][k] • The declaration is similar to one dimensional array. • int x[3][2] • x[0][0] x[0][1] • x[1][0] x[1][1] • x[2][0] x[2][1] • The size of this array is 6
  • 21. Set [0] x[0][0] x[0][1] x[1][0] x[1][1] x[2][0] x[2][1] The size of this array is 12 x[0][0] x[0][1] x[1][0] x[1][1] x[2][0] x[2][1] The size of this array is 6 row Example for 2D int x[3][2] Example for 3D int x[2][3][2] column row column set
  • 24. Output 2D array This coding shows how we allocate /display the array in 5 row and 2 column
  • 25. 2D array Output This coding shows relation operation in 2D array. 5 6 7 10 20 30 0 1 0 1 2 Array a 5+1 6+2 7+3 10+3 20+2 30+1 0 1 0 1 2 Array sum 1 2 3 3 2 1 0 1 0 1 2 Array b Allocate the 2D arrays Do the (+) operation Example: a[0][0]+ b[0][0]=5+1=6 a[0][1]+b[0][1]=6+2=8 … until a[1][1]+b[1][1]
  • 26. 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 0 1 2 0 1 0 1 Set (0) Set (1) The arrangement of the array Output For 3D array you can write like this or go to the next page 3D array
  • 27. For 3D array you can write like this or like previous page 3D array
  • 28. Example • Write a program to find the transpose matrix of order m x n;
  • 29. • Write a program to find y= 𝑖=1 𝑛 𝑖2 and sum of y using an array. n is defined by user Example 1
  • 31. Example 2 Write a program to find y= 𝑖=1 𝑛 𝑥2 and average of y using an array. X and n is defined by user #include <stdio.h> #include <math.h> int main() { int i,n, sums=0,array[i], average; printf("insert n: "); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&array[i]); sums+=array[i]*array[i]; average=sums/n; } printf("sums is %d",sums); printf("n average= %d", average); return 0; }  If have this mathematical problem 𝒊=𝟏 𝒏 𝒙 , the coding must be solve using array  Replace x  with array x [i] @ array[i]  Declare sums=0 at int/float. Follow how many sum in the question. Like this example only have 1 sum operation.  The coding also have to use “for” function Insert n 3 Max array are x[3]  you have to input 3 number Exp: array[0] insert 2 array[1] insert 4 array[2] insert 3 Output: i array[i] Sum+=array[i]*array[i] Average=sum/n 0 2 0+(2*2)=4 4/1=4 1 4 4+(4*4)=20 16/2=8 2 3 20+(3*3)=29 29/3=9 array[i]={2,3,4}
  • 32. Write a program to calculate the value of y, where xi is series of value in data set, n is number of values in data set and µ is mean of all values. The values of xi, and n are obtained from user input #include<studio.h> #includ<math.h> int main() { int n,i, x[10], float y, sumx sumx2, sumx3,sumx4, mean; scanf("%d",&n); for(i=0;i<n;i++); { scanf("%d",&x[i]); sumx+=x[i]*x[i] sumx2+=sqt(x[i]); sumx3+=x[i]; mean=sumx3/n; sumx4+=pow(x[i],3.0)*meanmean; } y=sumx/(n*sumx2)-sumx4; prinf("y= %d",y); return 0; } Example 3 Answer: Correct the error in the program and try to run it. y= 𝑖 𝑛 𝑥𝑖 2 𝑛 𝑖 𝑛 𝑥𝑖 1/2 − 𝑖 𝑛 𝑥𝑖 3 𝜇2 When, 𝜇 = 𝑖 𝑛 𝑥𝑖 𝑛
  • 33. Write a program to calculate the value of y, where xi is series of value in data set, n is number of values in data set and µ is mean of all values. The values of xi, and n are obtained from user input Exercise y= 𝑖 𝑛 𝑥𝑖𝜇 𝑛3 − 𝑖 𝑛 𝑥𝑖