Skip to main content

1-D & 2-D array

 #include<stdio.h>

int main()

{

    int marks[]={25,28,27};

    marks[3]=29;

    printf("The of student 1 is:-%d\n",marks[0]);

    printf("The of student 2 is:-%d\n",marks[1]);

    printf("The of student 3 is:-%d\n",marks[2]);

    printf("The of student 4 is:-%d\n",marks[3]);

    printf("The average of student marks is %d:-",(marks[0]+marks[1]+marks[2]+marks[3])/4);

    return 0;

}



    //Another code  2-D array

     #include<stdio.h>

int main()

{


    int marks[2][5]={{95,93,97,87,94},    here 2 represents no of rows & 5 s represents no of column.

                     {87,89,88,85,83}};


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

    {

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

        {

            printf("The value of %d, %d value of the array is %d\n",i,j,marks[i][j]);

        }



    }

    return 0;

}


    // Another code

    #include<stdio.h>

int main()

{

    int marks[5];                    //declare without initialization

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

    {

        printf("Enter the %d of the valve of array\n",i);

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

    }

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

    {

        printf("The value of %d value of the array is %d\n",i,marks[i]);

    }

    return 0;

}


    // Another code

     #include<stdio.h>

int main()

{

     int marks[5]={95,97,91,93,99};      // declare with initialization


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

    {

        printf("The value of %d value of the array is %d\n",i,marks[i]);

    }

    return 0;

}


Comments