What is Array in C Language

    one-dimensional Array in c

    Array Definition: Array is a collection of data of the same type. It can be used to store groups of data simultaneously.

    An array can store data of the same data type means an integer array can store only integer values, a character array can store only character values, and so on.

    We can not fetch knowledge from an array directly thus we tend to use index purposes.

    The array could be an assortment of comparable parts styles with a contiguous memory location. Learn C Language

    The array is an Associate in Nursing object that contains components of an identical information kind. it's an information structure wherever we have a tendency to store similar elements. 

    we will store solely a hard and fast set of components during an array. The array is index-based, the primary component of the array holds on at the zero indexes.

    What is Array in C Language
    What is Array in C Language

    Types of Array in C 

    There are two types of Array.

    1. Single-Dimensional Array

    2.Multidimensional Array

    Advantages of Array in C

    Code Optimization: Array makes the code optimized, we can retrieve or sort data efficiently.

    Random access: we can get any knowledge placed at an index position.

    Disadvantages of Array in C

    Size Limit: An array can store only the fixed size of elements in the array.


    Array in c programming syntax

    int a[]=new int[5];


    Here is the name of the array.

    int is the data type of array.

    The size of the array is five suggests that we can store most five values during this array.



    How To Initialization of array in C?

    int ar[]={10,20,30,40,50};

    int a[]=new int[5];

    ar[0]=50;

    ar[1]=40;

    ar[2]=30;

    ar[3]=20;

    ar[4]=10;



    one-dimensional array in c programming examples

    #include<studio.h>

    int main() 

    {

     int ar[5]={ 80,77,14,78,01 }; 

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

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

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

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

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


    *****OUTPUT*****

    Value is ar[0]:80

    Value is ar[1]:77

    Value is ar[2]:14

    Value is ar[3]:78

    Value is ar[4]:01



    How To Use Loop Array in C Program

    #include<stdio.h>

    int main ()

    int ar[]={80,77,14,78,01}; 

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

    {

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


    *****OUTPUT*****

    Value is ar[0]:80

    Value is ar[1]:77

    Value is ar[2]:14

    Value is ar[3]:78

    Value is ar[4]:01



    How To Use User input Method Array in C Program

    #include<studio.h>

    int main() 

    int a[5]; 

    printf("Enter element 1:"); 

    scanf("%d",&ar[0]); 

    printf("Enter element2:"); 

    scanf("%d",&ar[1]); 

    printf("Enter element 3:"); 

    scanf("%d",&ar[2]); 

    printf("Enter element 4:"); 

    scanf("%d",&ar[3]); 

    printf("Enter element 5:");

    scanf("%d",&ar[4]); 

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

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


    *****OUTPUT*****

    Enter element 1:80

    Enter element 2:77

    Enter element 3:14

    Enter element 4:78

    Enter element 5:01

    Value is ar[0]:80

    Value is ar[1]:77

    Value is ar[2]:14

    Value is ar[3]:78

    Value is ar[4]:01



    Two-dimensional array in data structure

    Array: Array is a collection of data of the same data type. It can be used to store groups of data simultaneously.

    The array can store data of the same data type means an integer array can store only integer value character array can store only character value and so on.

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

    The array is a collection of similar types of elements that have a contiguous memory location.

    An array is an object which contains elements of a similar data type. It is a data structure where we store similar elements. Earn Money

    We can store only a fixed set of elements in an array.

    The array is index-based, the first element of the array is stored at the 0 indexes.


    2-dimensional syntax

    int a[][]=new int[3][3];


    Here is the name of the array.

    int is the data type of array.

    The size of the array is 3x3 means we can store a maximum of 9 values in this array.


    How To Initialization 2-D array in C

    int ar[][]=new int[3][3];

    ar[0][0]=80;

    ar[0][1]=77;

    ar[0][2]=14;

    ar[1][0]=78;

    ar[1][1]=01;

    ar[1][2]=96;

    ar[2][0]=90;

    ar[2][1]=40;

    ar[2][2]=23;



    How To Use 2-D Array in C

    #include<stdio.h> 

    int main() 

    int ar[3][3]={{80,77,14},{78,01,96},

    {90,40,23}}; 

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

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

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

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

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

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

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

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

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

    }


    *****OUTPUT*****

    value at a[0][0]:80

    value at a[0][1]:77

    value at a[0][2]:14

    value at a[1][0]:78

    value at a[1][1]:01

    value at a[1][2]:96

    value at a[2][0]:90

    value at a[2][1]:40

    value at a[2][2]:23



    How To Use Loop. 2-D Array in C

    #include<stdio.h>

    int main()

    {

    int ar[3][3]={{80,77,14},{78,01,96},{90,40,23}};

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

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

    printf("%d ",ar[i][j]); 

    }

    printf("\n"); 


    *****OUTPUT*****

    80 77 14

    78 01 96

    90 40 23



    How To Use User input Method 2-D Array in C

    #include<stdio.h> 

    int main() 

    int a[3][3];

    int i,j; 

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

    for(j=0;j<=2;j++) 

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

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

    printf("Your Matrix is\n");

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

    for(j=0;j<=2;j++) 

    printf("%d ",a[i][j]); 

    printf("\n"); 

    }


    *****OUTPUT*****

    Enter Element:a[0][0]:80 

    Enter Element:a[0][1]:77 

    Enter Element:a[0][2]:14 

    Enter Element:a[1][0]:78 

    Enter Element:a[1][1]:01 

    Enter Element:a[1][2]:96 

    Enter Element:a[2][0]:90 

    Enter Element:a[2][1]:40 

    Enter Element:a[2][2]:23

    Your Matrix is

    80 77 14

    78 01 96

    90 40 23



    Array Advanced Program in C Language


    How to sort array in ascending order in c

    #include<stdio.h>

    int 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("Assending Order Array Elem1ents\n");

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

    {

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

    }

    }

    *****OUTPUT*****

    Enter Array Size:5

    Enter Array Elements[0]:12

    Enter Array Elements[1]:54

    Enter Array Elements[2]:67

    Enter Array Elements[3]:45

    Enter Array Elements[4]:98


    Ascending Order Array Elem1ents

    Array Element[0]:12

    Array Element[1]:45

    Array Element[2]:54

    Array Element[3]:67

    Array Element[4]:98



    How to sort arrays in Descending order in C

    #include<stdio.h>

    int main()

    {

    int a[10],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("Desending Order Array Elem1ents\n");

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

    {

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

    }

    }


    *****OUTPUT*****
    Enter Array Size:5
    Enter Array Elements[0]:65
    Enter Array Elements[1]:76
    Enter Array Elements[2]:64
    Enter Array Elements[3]:1
    Enter Array Elements[4]:24

    Descending Order Array Elem1ents
    Array Element[0]:76
    Array Element[1]:65
    Array Element[2]:64
    Array Element[3]:24
    Array Element[4]:1


    Array Insert in the Beginning position C language

    # includes <stdio.h>

    int 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:");

    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]);

    }

    }

    *****OUTPUT*****

    Enter Array Size:5

    Enter Array Element[0]:3

    Enter Array Element[1]:4

    Enter Array Element[2]:7

    Enter Array Element[3]:6

    Enter Array Element[4]:5

    Enter Array Element in the insert at Begining:45


    After Insertion Array Element

    New Array Element[0]:45

    New Array Element[1]:3

    New Array Element[2]:4

    New Array Element[3]:7

    New Array Element[4]:6

    New Array Element[5]:5



    Array Insert in the Last position C language

    # includes <stdio.h>

    int main()

    {

    int a[10],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 insert into ending Position:");

    scanf("%d",&ins);

    n=n+1;

    a[n-1]=ins;

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

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

    {

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

    }

    }

    *****OUTPUT*****

    Enter array size:5

    enter array element[0]:6

    enter array element[1]:5

    enter array element[2]:7

    enter array element[3]:3

    enter array element[4]:76

    Enter Array Element insert into ending Position:88

    After Insert Array Element

    New array Element[0]:6

    New array Element[1]:5

    New array Element[2]:7

    New array Element[3]:3

    New array Element[4]:76

    New array Element[5]:88



    Search element in array using loop in c

    #include<stdio.h>

    int main()

    {

    int a[100],n,p,s;

    printf("Enter Array Size:");

    scanf("%d",&n);

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

    {

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

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

    }

    printf("Enter Array Element Search:");

    scanf("%d",&s);

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

    {

    if(s==a[i])

    {

    printf("Array Element found Postion[%d]:%d",i,a[i]);

    }

    }

    }

    *****OUTPUT*****

    Enter Array Size:5

    Enter Array Elements[0]:5

    Enter Array Elements[1]:4

    Enter Array Elements[2]:7

    Enter Array Elements[3]:3

    Enter Array Elements[4]:8

    Enter Array Element Search:7


    Array Element found Postion[2]:7



    How do you sort a 2D array using arrays sort?

    #include<stdio.h>

    int main()

    {

    int a[3][3],r,c,t;

    printf("Enter Row:");

    scanf("%d",&r);

    printf("Enter Colume:");

    scanf("%d",&c);

    printf("-----------------------------------------\n");

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

    {

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

    {

    printf("Enter Array Element Row and Colume[%d][%d]:",i,j);

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

    }

    }

    printf("-----------------------------------------\n");

    printf("2-D Array Matrix\n");

    printf("-----------------------------------------\n");

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

    {

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

    {

    printf(" %d ",a[i][j]);

    }

    printf("\n");

    }

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

    {

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

    {

    for(int i1=0;i1<r;i1++)

    {

    for(int j1=0;j1<c;j1++)

    {

    if(a[i][j]<a[i1][j1])

    {

    t=a[i][j];

    a[i][j]=a[i1][j1];

    a[i1][j1]=t;

    }

    }

    }

    }

    }

    printf("-----------------------------------------\n");

    printf(" Your 2-D Array Shorted\n");

    printf("-----------------------------------------\n");

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

    {

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

    {

    printf(" %d ",a[i][j]);

    }

    printf("\n");

    }

    printf("-----------------------------------------\n");

    }

    *****OUTPUT*****

    Enter Row:3

    Enter Colume:3

    -----------------------------------------

    Enter Array Element Row and Colume[0][0]:56

    Enter Array Element Row and Colume[0][1]:4

    Enter Array Element Row and Colume[0][2]:5

    Enter Array Element Row and Colume[1][0]:68

    Enter Array Element Row and Colume[1][1]:3

    Enter Array Element Row and Colume[1][2]:4

    Enter Array Element Row and Colume[2][0]:9

    Enter Array Element Row and Colume[2][1]:76

    Enter Array Element Row and Colume[2][2]:4

    -----------------------------------------

    2-D Array Matrix

    -----------------------------------------

     56  4  5

     68  3  4

     9  76  4

    -----------------------------------------

     Your 2-D Array Shorted

    -----------------------------------------

     3  4  4

     4  5  9

     56  68  76

    -----------------------------------------




    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.