Single Dimensional Array Example Program in C Programming
On this page (8sections)
About this program
This is an example program in c array example programs. Read the concept first: C Array, then study the code and output below.
Definition
An array is a collection of data that holds homogeneous values. That means values should be in same type
Syntax
type variable_name[size]
Details of Array
int varName[10];
Here, varName has 10 containers,
varName[0], varName[1] to varName[9]
For example,
Array values stores like below structure,
int value[6] = {5,10,15,20,25,30};
Value[0] = 5
Value[1] : 10
Value[2] : 15
Value[3] : 20
Value[4] : 25
Value[5] : 30
Example Program for Single Dimensional Array
/* Example Program For Single Dimensional Array In C Programming Language
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
// Header Files
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
// declaring and Initialising array in C
int value[6] = {5,10,15,20,25,30};
for (i=0;i<6;i++)
{
// Accessing each variable using for loop
printf("Position : [%d] , Value : %d \n", i, value[i]);
}
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output:
Position : [0] , Value : 5
Position : [1] , Value : 10
Position : [2] , Value : 15
Position : [3] , Value : 20
Position : [4] , Value : 25
Position : [5] , Value : 30
Related Pages
Learn the concept first, then study the code:
- C Programs — Browse all C Programs.
- C Array — Concept — arrays, indexing and multidimensional arrays.
- Sum of Array C Example Program — More in c array example programs.
- Read Array and Print Array C Example Program — More in c array example programs.