One Dimensional Array in C Definition| Single Dimensional Array

Single-Array in C: Array is a collection of data types . It is used to store a group of data simultaneously. It can be store data of same data types means an integer array can be store only integer value, character array can store only character value. 

We can not fetch data from array directly therefore we use index point.

Array indexing of array always start with 0. Index value is always an integer number. Array may be of any data type like int, char and float.

Single Array in C Programming| Shorting Array in Full Explanation
Single Array in C Programming| Shorting Array in Full Explanation

    What is Syntax of Array in C

    data_type array_name[array_size]={Array_Elements};


    int a[5]=int[10,12,14,15,78];


    One Dimensional Array in C Programming Examples

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[5]={10,40,30,23,34};

    printf("value of is [0]:%d\n",a[0]);

    printf("value of is [1]:%d\n",a[1]);

    printf("value of is [2]:%d\n",a[2]);

    printf("value of is [3]:%d\n",a[3]);

    printf("value of is [4]:%d\n",a[4]);

    getch();

    }


    **********OUTPUT**********

    value of is [0]: 10

    value of is [1]: 40

    value of is [2]: 30

    value of is [3]: 23

    value of is [4]: 34


    Array in C Programming Examples Using Loop

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[5]={10,40,30,23,34};

    for(int i=0;i<5;i++)

    {

     printf("value of is [%d]:%d\n",i,a[i]);

    }

    getch();

    }


    **********OUTPUT**********

    value of is [0]: 10

    value of is [1]: 40

    value of is [2]: 30

    value of is [3]: 23

    value of is [4]: 34


    Array in C Programming Examples user input and output

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[5];

    printf("Enter array Element1:");

    scanf("%d",&a[0];

    printf("Enter array Element2:");

    scanf("%d",&a[1];

    printf("Enter array Element3:");

    scanf("%d",&a[2];

    printf("Enter array Element4:");

    scanf("%d",&a[3];

    printf("Enter array Element5:");

    scanf("%d",&a[4];

    printf("Printing Data...\n");

    for(int i=0;i<5;i++)

    {

     printf("Value of is[%d]=%d\n",i,a[i]);

    }

    getch();

    }


    **********OUTPUT**********

    Enter Element1:10

    Enter Element1:40

    Enter Element1:30

    Enter Element1:23

    Enter Element1:34


    Printing Data...

    value of is [0]: 10

    value of is [1]: 40

    value of is [2]: 30

    value of is [3]: 23

    value of is [4]: 34


    Array in C Programming Examples user input using for Loop

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[5];

     int i,j;

    for(i=0;i<5;i++)

    {

       printf("Enter Array Element[%d]:",i);

       scanf("%d",&a[i]);

    }

    printf("Printing Data...\n");

    for(int i=0;i<5;i++)

    {

     printf("Value of is[%d]:%d\n",i,a[i]);

    }

    getch();

    }


    **********OUTPUT**********

    Enter Element[0]:10

    Enter Element[1]:40

    Enter Element[2]:30

    Enter Element[3]:23

    Enter Element[4]:34


    Printing Data...

    value of is [0]: 10

    value of is [1]: 40

    value of is [2]: 30

    value of is [3]: 23

    value of is [4]: 34


    Sum of Array Elements in C Hackerrank Solution

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[20];

     int i,n,sum=0;

    printf("How Many Elements you want to Enter:");

    scanf("%d',&n);

    for(i=0;i<n;i++)

    {

       printf("Enter Array Element[%d]:",i);

       scanf("%d",&a[i]);

    sum=sum+a[i];

    }

    printf("Total Sum of Element:%d",sum); 


    getch();

    }


    **********OUTPUT**********

    How Many Elements you want to Enter:5

    Enter Array Element[0]:10

    Enter Array Element[1]:40

    Enter Array Element[2]:30

    Enter Array Element[3]:23

    Enter Array Element[4]:34


    Total Sum of number:137


    Addition of One Dimensional Array in C

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[20],b[20],c[20];

     int n;

    printf("Enter First Array Elements:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

       printf("Enter Array Element[%d]:",i);

       scanf("%d",&a[i]);

    }

    printf("First Array Element\n\n");

    for(int i=0;i<n;i++)

    {

    printf("First Array Data[%d]:%d\n",i,a[i]);

    }


    printf("Enter Second Array Elements:");

    scanf("%d",&n);

    for(int j=0;j<n;j++)

    {

       printf("Enter Array Element[%d]:",j);

       scanf("%d",&b[j]);

    }

    printf("Second Array Element\n\n");

    for(int j=0;j<n;j++)

    {

    printf("Second Array Data[%d]:%d\n",j,a[j]);

    }


    printf("Addition of Matrix\n\n");

    for(int k=0;k<n;k++)

    {

    c[k]=a[k]+b[k];

    printf("%d\n",c[k]);

    }

    getch();


    }


    **********OUTPUT**********

    Enter First Array Elements:2

    Enter Array Element[0]:2

    Enter Array Element[1]:2

    First Array Element


    First Array Data[0]:2

    First Array Data[1]:2


    Enter Second Array Elements:2

    Enter Array Element[0]:2

    Enter Array Element[1]:2

    Second Array Element


    Second Array Data[0]:2

    Second Array Data[1]:2


    Addition of Matrix

    4

    4


    One Dimensional Array Print All Even Number

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int a[100],n;

    printf("Enter size of Array Element:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Element[%d]:",i);

    scanf("%d",&a[i]);

    }

    printf("Printing Array Element Data\n");

    for(int i=0;i<n;i++)

    {

    printf("Array Data[%d]:%d\n",i,a[i]);

    }

    printf("Printing All Even Array Element\n");

     

    for(int j=0;j<n;j++)

    {

    if(a[j]%2==0)

    printf("Even Array Element[%d]:%d\n",j,a[j]);

    }

    getch();

    }


    **********OUTPUT**********

    Enter size of Array Element:5

    Enter Array Element[0]:15

    Enter Array Element[1]:58

    Enter Array Element[2]:72

    Enter Array Element[3]:23

    Enter Array Element[4]:80


    Printing Array Element Data

    Array Data[0]:15

    Array Data[1]:58

    Array Data[2]:72

    Array Data[3]:23

    Array Data[4]:80


    Printing All Even Array Element

    Even Array Element[1]:58

    Even Array Element[2]:72

    Even Array Element[4]:80


    One Dimensional Array Print All Odd Number

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[100],n;

     printf("Enter size of Array Element:");

     scanf("%d",&n);

     for(int i=0;i<n;i++)

     {

      printf("Enter Array Element[%d]:",i);

      scanf("%d",&a[i]);

     }

     printf("Printing Array Element Data\n");

     for(int i=0;i<n;i++)

     {

      printf("Array Data[%d]:%d\n",i,a[i]);

     }

     printf("Printing All Odd Array Element\n");

     

     for(int j=0;j<n;j++)

     {

      if(a[j]%2!=0)

      printf("Odd Array Element[%d]:%d\n",j,a[j]);

     }

    getch();

    }


    **********OUTPUT**********

    Enter size of Array Element:5

    Enter Array Element[0]:15

    Enter Array Element[1]:58

    Enter Array Element[2]:72

    Enter Array Element[3]:23

    Enter Array Element[4]:80


    Printing Array Element Data

    Array Data[0]:15

    Array Data[1]:58

    Array Data[2]:72

    Array Data[3]:23

    Array Data[4]:80


    Printing All Odd Array Element

    Odd Array Element[1]:15

    Odd Array Element[2]:23


    One Dimensional Array Find Maximum Value in C

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int a[100],n,max;

    printf("Enter size of Array Element:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Element[%d]:",i);

    scanf("%d",&a[i]);

    max=a[0];

    }

    printf("Printing Array Element Data\n");

    for(int i=0;i<n;i++)

    {

    printf("Array Data[%d]:%d\n",i,a[i]);

    }

    for(int i=0;i<n;i++)

    {

    if(max<a[i])

    max=a[i];

    }

    printf("Maximum Value:%d",max);

    getch();  

    }


    **********OUTPUT**********

    Enter size of Array Element:5

    Enter Array Element[0]:76

    Enter Array Element[1]:55

    Enter Array Element[2]:44

    Enter Array Element[3]:23

    Enter Array Element[4]:89


    Printing Array Element Data

    Array Data[0]:76

    Array Data[1]:55

    Array Data[2]:44

    Array Data[3]:23

    Array Data[4]:89


    Maximum Value:89


    One Dimensional Array Minimum Array Element Example

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

     int a[100],n,min;

     printf("Enter size of Array Element:");

     scanf("%d",&n);

     for(int i=0;i<n;i++)

     {

      printf("Enter Array Element[%d]:",i);

      scanf("%d",&a[i]);

      min=a[0];

     }

     printf("Printing Array Element Data\n");

     for(int i=0;i<n;i++)

     {

      printf("Array Data[%d]:%d\n",i,a[i]);

     }

     for(int i=0;i<n;i++)

     {

      if(min>a[i])

      max=a[i];

     }

     printf("Maximum Value:%d",max);

    getch();  

    }


    **********OUTPUT**********

    Enter size of Array Element:5

    Enter Array Element[0]:76

    Enter Array Element[1]:55

    Enter Array Element[2]:44

    Enter Array Element[3]:23

    Enter Array Element[4]:89


    Printing Array Element Data

    Array Data[0]:76

    Array Data[1]:55

    Array Data[2]:44

    Array Data[3]:23

    Array Data[4]:89;


    Minimum Value:23


    One Dimensional Array Ascending Order Array Element

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int a[100],n,t;

    printf("Enter Array Size:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Elements[%d]:",i);

    scanf("%d",&a[i]);

    }

    for(int i=0;i<n;i++)

    {

    for(int j=i+1;j<n;j++)

    {

    if(a[i]>a[j])

    {

    t=a[i];

    a[i]=a[j];

    a[j]=t;

    }

    }

    }

    printf("Ascending Order Array Elements\n");

    for(int i=0;i<n;i++)

    {

    printf("Array Element[%d]:%d\n",i,a[i]);

    }

    getch();

    }


    **********OUTPUT**********

    Enter Array Size:5

    Enter Array Elements[0]:34

    Enter Array Elements[1]:23

    Enter Array Elements[2]:5

    Enter Array Elements[3]:65

    Enter Array Elements[4]:4


    Ascending Order Array Elements

    Array Element[0]:4

    Array Element[1]:5

    Array Element[2]:23

    Array Element[3]:34

    Array Element[4]:65


    One Dimensional Array Descending Order Array Element

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int a[100],n,t;

    printf("Enter Array Size:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Elements[%d]:",i);

    scanf("%d",&a[i]);

    }

    for(int i=0;i<n;i++)

    {

    for(int j=i+1;j<n;j++)

    {

    if(a[i]>a[j])

    {

    t=a[i];

    a[i]=a[j];

    a[j]=t;

    }

    }

    }

    printf("Descending Order Array Elements\n");

    for(int i=0;i<n;i++)

    {

    printf("Array Element[%d]:%d\n",i,a[i]);

    }

    getch();

    }


    **********OUTPUT**********

    Enter Array Size:5

    Enter Array Elements[0]:65

    Enter Array Elements[1]:45

    Enter Array Elements[2]:1

    Enter Array Elements[3]:23

    Enter Array Elements[4]:5


    Descending Order Array Elements

    Array Element[0]:65

    Array Element[1]:45

    Array Element[2]:23

    Array Element[3]:5

    Array Element[4]:1


    One Dimensional Array Last Insertion Array Element

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int a[100],n,l;

    printf("Enter array Size:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Element[%d]:",i);

    scanf("%d",&a[i]);

    }

    printf("Enter New Array Element Insert:");

    scanf("%d",&l);

    a[n]=l;

    n++;

    for(int i=0;i<n;i++)

    printf("New Array[%d]:%d\n",i,a[i]);

    }

    getch();

    }



    **********OUTPUT**********

    Enter array Size:5

    Enter Array Element[0]:65

    Enter Array Element[1]:45

    Enter Array Element[2]:34

    Enter Array Element[3]:87

    Enter Array Element[4]:87


    Enter New Array Element Insert:100


    After Insertion Array Element

    New Array[0]:65

    New Array[1]:45

    New Array[2]:34

    New Array[3]:87

    New Array[4]:87

    New Array[5]:100


    One Dimensional Array First Insertion Array Element

    #include<stdio.h>

    #include<conio.h>


    void main()

    {

    int a[100],n,ins;

    printf("Enter Array Size:");

    scanf("%d",&n);

    for(int i=0;i<n;i++)

    {

    printf("Enter Array Element[%d]:",i);

    scanf("%d",&a[i]);

    }

    printf("Enter Array Element in insert at Begining Position:");

    scanf("%d",&ins);

    n++;

    for(int i=n;i>1;i--)

    {

    a[i-1]=a[i-2];

    }

    a[0]=ins;

    printf("After Insertion Array Element\n");

    for(int i=0;i<n;i++)

    {

    printf("New Array Element[%d]:%d\n",i,a[i]);

    }

    getch();

    }



    **********OUTPUT**********

    Enter Array Size:5

    Enter Array Element[0]:76

    Enter Array Element[1]:45

    Enter Array Element[2]:34

    Enter Array Element[3]:65

    Enter Array Element[4]:87


    Enter Array Element in insert at Begining Position:100


    After Insertion Array Element

    New Array Element[0]:100

    New Array Element[1]:76

    New Array Element[2]:45

    New Array Element[3]:34

    New Array Element[4]:65

    New Array Element[5]:87