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.
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
#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
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

Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptx
MrMaster11
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Array
ArrayArray
Session 4
Session 4Session 4
Array
ArrayArray
Arrays
ArraysArrays
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
Munazza-Mah-Jabeen
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
AnisZahirahAzman
 
2 Arrays & Strings.pptx
2 Arrays & Strings.pptx2 Arrays & Strings.pptx
2 Arrays & Strings.pptx
aarockiaabinsAPIICSE
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
fixocin377
 
Arrays
ArraysArrays
Arrays
Neeru Mittal
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
chanchal ghosh
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Arrays
ArraysArrays

Similar to Array-part1 (20)

Array assignment
Array assignmentArray assignment
Array assignment
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptx
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Array
ArrayArray
Array
 
Session 4
Session 4Session 4
Session 4
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
2 Arrays & Strings.pptx
2 Arrays & Strings.pptx2 Arrays & Strings.pptx
2 Arrays & Strings.pptx
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Arrays
ArraysArrays
Arrays
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Arrays
ArraysArrays
Arrays
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 

Recently uploaded

Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 

Recently uploaded (20)

Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 

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.
  • 14.
  • 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
  • 18.
  • 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
  • 22.
  • 23.
  • 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 − 𝑖 𝑛 𝑥𝑖