SlideShare a Scribd company logo
1 of 19
Download to read offline
BY GOKILA.R
Why ARRAY?
ARRAY DEFINITION
 An array is a collection of similar data elements.
These data elements have the same data type.
 The elements of the array are stored in
consecutive memory locations and are referenced
by an index (also known as the subscript).
TYPES OF ARRAYS
 One dimensional array
 Two dimensional array
 Multi dimensional array
ARRAY DECLARATION
In C, arrays are declared using the following syntax:
type name[size];
 Data type—the kind of values it can store, for example, int, char, float,
double.
 Name—to identify the array.
 Size—the maximum number of values that the array can hold.
For example,
int marks[10];//mark contains 10 elements.index starts from zero.
 dataType arrayName[arraySize];
float marks[5];
 It can hold 5 float values.
 Note:the size and type of an array cannot be changed once it is declared.
Memory representation of 10 elements
Declaring arrays of different data types and sizes
Calculating the Length of an Array
 The length of an array is given by the number of elements stored in it. The
general formula to calculate the length of an array is
Length = upper_bound – lower_bound + 1
 where upper_bound is the index of the last element and lower_bound is the
index of the first element in the array.
Example : Let Age[5] be an array of integers such that
Age[0] = 2, Age[1] = 5, Age[2] = 3, Age[3] = 1, Age[4] = 7
Show the memory representation of the array and calculate its length.
Solution
The memory representation of the array Age[5] is given as below.
Age[ 0] Age[1] Age[2] Age[3] Age[4]
Length = upper_bound – lower_bound + 1
Here, lower_bound = 0, upper_bound = 4
Therefore, length = 4 – 0 + 1 = 5
2 5 3 1 7
ARRAY INITIALIZATION
 It is possible to initialize an array during declaration.
For example,
 int mark[5] = {19, 10, 8, 17, 9};
/*You can also initialize an array like this.*/
 int mark[] = {19, 10, 8, 17, 9};
/*Here, we haven't specified the size. However, the
compiler knows its size is 5 as we are initializing it with
5 elements.*/
int mark[5] = {19, 10, 8, 17, 9};
mark[0] is equal to 19
mark[1] is equal to 10
mark[2] is equal to 8
 mark[3] is equal to 17
 mark[4] is equal to 9
ARRAY INTIALIZATION
Access Array Elements
 You can access elements of an array by indices.
 Suppose you declared an array mark as above. The first
element is mark[0], the second element is mark[1] and
so on.
Note:
 Arrays have 0 as the first index, not 1. In this
example, mark[0] is the first element.
 If the size of an array is n, to access the last element,
the n-1 index is used. In this example, mark[4]
 Suppose the starting address of mark[0] is 2120d.
Then, the address of the mark[1] will be 2124d.
Similarly, the address of mark[2] will be 2128d and so
on.
This is because the size of a float is 4 bytes.
Calculating the Address of Array Elements
 Base address, that is the address of the first element in the array.
FORMULA
 Address of data element, A[k] = BA(A) + w(k – lower_bound)
 Here, A is the array, k is the index of the element of which we have to calculate the
address, BA is the base address of the array A, and w is the size of one element in
memory, for example, size of int is 2.
CHANGE VALUE OF ARRAY ELEMENTS
int mark[5] = {19, 10, 8, 17, 9}
mark[2] = -1;
// make the value of the third element to -1
mark[4] = 0;
// make the value of the fifth element to 0
scanf("%d", &mark[2]); //take input and store it in the
3rd element
scanf("%d", &mark[i-1]);/ // take input and store it in
the ith element
PRINT AN INDIVIDUAL ELEMENT OF AN ARRAY
// print the first element of the array printf("%d",
mark[0]);
// print the third element of the array printf("%d",
mark[2]);
 // print ith element of the array
printf("%d", mark[i-1]);
Program to take 5 values from the user and store them in an array
#include <stdio.h>
int main()
{
int values[5];
printf("Enter 5 integers: "); // taking input and storing it in an array
for(int i = 0; i < 5; ++i) // for loop to take 5 inputs from the user and store in array
{
scanf("%d", &values[i]);
}
printf("Displaying integers: "); // printing elements of an array
for(int i = 0; i < 5; ++i) //another for loop, these elements are displayed on the screen.
{
printf("%dn", values[i]);
}
return 0;
}
ASSIGNMENT
1. Summary of array upto you have learnt today in
introduction to c programming note with all programs.
2.Write a C program to find the sum and average of a
given numbers using array.
THANK YOU
ANY QUERIES??

More Related Content

What's hot

What's hot (20)

Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Array in c
Array in cArray in c
Array in c
 
Arrayspl
ArraysplArrayspl
Arrayspl
 
Array C programming
Array C programmingArray C programming
Array C programming
 
C programming , array 2020
C programming , array 2020C programming , array 2020
C programming , array 2020
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in C
Array in CArray in C
Array in C
 
Array
ArrayArray
Array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 

Similar to Array (20)

Array
ArrayArray
Array
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
Arrays
ArraysArrays
Arrays
 
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
 
PPt. on An _Array in C
PPt. on An _Array in CPPt. on An _Array in C
PPt. on An _Array in C
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Arrays
ArraysArrays
Arrays
 
C_Arrays.pptx
C_Arrays.pptxC_Arrays.pptx
C_Arrays.pptx
 
2-Arrays.pdf
2-Arrays.pdf2-Arrays.pdf
2-Arrays.pdf
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Module7
Module7Module7
Module7
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 

More from vrgokila

evaluation technique uni 2
evaluation technique uni 2evaluation technique uni 2
evaluation technique uni 2vrgokila
 
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNS
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNSUnit 2 HCI DESIGN RULES AND DESIGN PATTERNS
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNSvrgokila
 
Unit 2 hci
Unit 2 hciUnit 2 hci
Unit 2 hcivrgokila
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updatedvrgokila
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingvrgokila
 

More from vrgokila (6)

evaluation technique uni 2
evaluation technique uni 2evaluation technique uni 2
evaluation technique uni 2
 
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNS
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNSUnit 2 HCI DESIGN RULES AND DESIGN PATTERNS
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNS
 
Unit 2 hci
Unit 2 hciUnit 2 hci
Unit 2 hci
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
 

Recently uploaded

TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
Triangulation survey (Basic Mine Surveying)_MI10412MI.pptx
Triangulation survey (Basic Mine Surveying)_MI10412MI.pptxTriangulation survey (Basic Mine Surveying)_MI10412MI.pptx
Triangulation survey (Basic Mine Surveying)_MI10412MI.pptxRomil Mishra
 
March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...
March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...
March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...gerogepatton
 
Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...
Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...
Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...shreenathji26
 
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.elesangwon
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProRay Yuan Liu
 
input buffering in lexical analysis in CD
input buffering in lexical analysis in CDinput buffering in lexical analysis in CD
input buffering in lexical analysis in CDHeadOfDepartmentComp1
 
Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...
Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...
Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...IJAEMSJORNAL
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
Detection&Tracking - Thermal imaging object detection and tracking
Detection&Tracking - Thermal imaging object detection and trackingDetection&Tracking - Thermal imaging object detection and tracking
Detection&Tracking - Thermal imaging object detection and trackinghadarpinhas1
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Romil Mishra
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical training70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical trainingGladiatorsKasper
 
22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...
22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...
22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...KrishnaveniKrishnara1
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
ADM100 Running Book for sap basis domain study
ADM100 Running Book for sap basis domain studyADM100 Running Book for sap basis domain study
ADM100 Running Book for sap basis domain studydhruvamdhruvil123
 
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 
priority interrupt computer organization
priority interrupt computer organizationpriority interrupt computer organization
priority interrupt computer organizationchnrketan
 

Recently uploaded (20)

TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
Triangulation survey (Basic Mine Surveying)_MI10412MI.pptx
Triangulation survey (Basic Mine Surveying)_MI10412MI.pptxTriangulation survey (Basic Mine Surveying)_MI10412MI.pptx
Triangulation survey (Basic Mine Surveying)_MI10412MI.pptx
 
March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...
March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...
March 2024 - Top 10 Read Articles in Artificial Intelligence and Applications...
 
Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...
Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...
Introduction to Artificial Intelligence: Intelligent Agents, State Space Sear...
 
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision Pro
 
input buffering in lexical analysis in CD
input buffering in lexical analysis in CDinput buffering in lexical analysis in CD
input buffering in lexical analysis in CD
 
Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...
Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...
Guardians of E-Commerce: Harnessing NLP and Machine Learning Approaches for A...
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
Detection&Tracking - Thermal imaging object detection and tracking
Detection&Tracking - Thermal imaging object detection and trackingDetection&Tracking - Thermal imaging object detection and tracking
Detection&Tracking - Thermal imaging object detection and tracking
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical training70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical training
 
22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...
22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...
22CYT12 & Chemistry for Computer Systems_Unit-II-Corrosion & its Control Meth...
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
ADM100 Running Book for sap basis domain study
ADM100 Running Book for sap basis domain studyADM100 Running Book for sap basis domain study
ADM100 Running Book for sap basis domain study
 
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
ASME-B31.4-2019-estandar para diseño de ductos
ASME-B31.4-2019-estandar para diseño de ductosASME-B31.4-2019-estandar para diseño de ductos
ASME-B31.4-2019-estandar para diseño de ductos
 
priority interrupt computer organization
priority interrupt computer organizationpriority interrupt computer organization
priority interrupt computer organization
 

Array

  • 3. ARRAY DEFINITION  An array is a collection of similar data elements. These data elements have the same data type.  The elements of the array are stored in consecutive memory locations and are referenced by an index (also known as the subscript).
  • 4. TYPES OF ARRAYS  One dimensional array  Two dimensional array  Multi dimensional array
  • 5. ARRAY DECLARATION In C, arrays are declared using the following syntax: type name[size];  Data type—the kind of values it can store, for example, int, char, float, double.  Name—to identify the array.  Size—the maximum number of values that the array can hold. For example, int marks[10];//mark contains 10 elements.index starts from zero.  dataType arrayName[arraySize]; float marks[5];  It can hold 5 float values.  Note:the size and type of an array cannot be changed once it is declared.
  • 7. Declaring arrays of different data types and sizes
  • 8. Calculating the Length of an Array  The length of an array is given by the number of elements stored in it. The general formula to calculate the length of an array is Length = upper_bound – lower_bound + 1  where upper_bound is the index of the last element and lower_bound is the index of the first element in the array. Example : Let Age[5] be an array of integers such that Age[0] = 2, Age[1] = 5, Age[2] = 3, Age[3] = 1, Age[4] = 7 Show the memory representation of the array and calculate its length. Solution The memory representation of the array Age[5] is given as below. Age[ 0] Age[1] Age[2] Age[3] Age[4] Length = upper_bound – lower_bound + 1 Here, lower_bound = 0, upper_bound = 4 Therefore, length = 4 – 0 + 1 = 5 2 5 3 1 7
  • 9. ARRAY INITIALIZATION  It is possible to initialize an array during declaration. For example,  int mark[5] = {19, 10, 8, 17, 9}; /*You can also initialize an array like this.*/  int mark[] = {19, 10, 8, 17, 9}; /*Here, we haven't specified the size. However, the compiler knows its size is 5 as we are initializing it with 5 elements.*/
  • 10. int mark[5] = {19, 10, 8, 17, 9}; mark[0] is equal to 19 mark[1] is equal to 10 mark[2] is equal to 8  mark[3] is equal to 17  mark[4] is equal to 9
  • 12. Access Array Elements  You can access elements of an array by indices.  Suppose you declared an array mark as above. The first element is mark[0], the second element is mark[1] and so on.
  • 13. Note:  Arrays have 0 as the first index, not 1. In this example, mark[0] is the first element.  If the size of an array is n, to access the last element, the n-1 index is used. In this example, mark[4]  Suppose the starting address of mark[0] is 2120d. Then, the address of the mark[1] will be 2124d. Similarly, the address of mark[2] will be 2128d and so on. This is because the size of a float is 4 bytes.
  • 14. Calculating the Address of Array Elements  Base address, that is the address of the first element in the array. FORMULA  Address of data element, A[k] = BA(A) + w(k – lower_bound)  Here, A is the array, k is the index of the element of which we have to calculate the address, BA is the base address of the array A, and w is the size of one element in memory, for example, size of int is 2.
  • 15. CHANGE VALUE OF ARRAY ELEMENTS int mark[5] = {19, 10, 8, 17, 9} mark[2] = -1; // make the value of the third element to -1 mark[4] = 0; // make the value of the fifth element to 0 scanf("%d", &mark[2]); //take input and store it in the 3rd element scanf("%d", &mark[i-1]);/ // take input and store it in the ith element
  • 16. PRINT AN INDIVIDUAL ELEMENT OF AN ARRAY // print the first element of the array printf("%d", mark[0]); // print the third element of the array printf("%d", mark[2]);  // print ith element of the array printf("%d", mark[i-1]);
  • 17. Program to take 5 values from the user and store them in an array #include <stdio.h> int main() { int values[5]; printf("Enter 5 integers: "); // taking input and storing it in an array for(int i = 0; i < 5; ++i) // for loop to take 5 inputs from the user and store in array { scanf("%d", &values[i]); } printf("Displaying integers: "); // printing elements of an array for(int i = 0; i < 5; ++i) //another for loop, these elements are displayed on the screen. { printf("%dn", values[i]); } return 0; }
  • 18. ASSIGNMENT 1. Summary of array upto you have learnt today in introduction to c programming note with all programs. 2.Write a C program to find the sum and average of a given numbers using array.