DOUBLE DIMENSION ARRAY

      1.PRINT ALL THE ELEMENT OF DOUBLE                            DIMENSION ARRAY:

#include<stdio.h> 
int main()
{
   int array[3][3]={{7,8,9},{1,2,3},{4,5,6}};
   int i,j;
   printf("Elements of array is given below\n");
    for(i=0;i<=2;i++)
    {
    for(j=0;j<=2;j++)
    {
    printf("%d ",array[i][j]);
}
printf("\n");
}
}

•Output 

Elements of array is given below
7 8 9
1 2 3
4 5 6

    2.USER INPUT IN DOUBLE DIMENSION                                      ARRAY: 

#include<stdio.h> 
int main()
{
   int array[50][50],row,col;
   int i,j;
   printf("Enter row \n");
   scanf("%d",&row);
   printf("Enter col \n");
   scanf("%d",&col);
   printf("Enter %d integer value one by one\n",row*col);
    for(i=0;i<row;i++)
    {
    for(j=0;j<col;j++)
    {
    scanf("%d",&array[i][j]);
}
}
   
   printf("Elements of array is given below\n");
    for(i=0;i<row;i++)
    {
    for(j=0;j<col;j++)
    {
    printf("%d ",array[i][j]);
}
printf("\n");
}
}

•Output 

Enter row
2
Enter col
2
Enter 4 integer value one by one
4
5
6
9
Elements of array is given below
4 5
6 9

   3.FIND THE SUM OF ALL THE ELEMENT IN ARRAY: 

#include<stdio.h> 
int main()
{
   int array[50][50],row,col,sum=0;
   int i,j;
   printf("Enter row \n");
   scanf("%d",&row);
   
   printf("Enter col \n");
   scanf("%d",&col);
   printf("Enter %d integer value one by one\n",row*col);
    for(i=0;i<row;i++)
    {
    for(j=0;j<col;j++)
    {
    scanf("%d",&array[i][j]);
}
}
   
   printf("Elements of array is given below\n");
    for(i=0;i<row;i++)
    {
    for(j=0;j<col;j++)
    {
    printf("%d ",array[i][j]);
    sum=sum+array[i][j];
}
printf("\n");
}
printf("Total sum =%d",sum);
}

•Output 

Enter row
2
Enter col
2
Enter 4 integer value one by one
4
5
6
9
Elements of array is given below
4 5
6 9
Total sum =24

      4.ADDITION OF DOUBLE DIMENSION ARRAY:  

#include<stdio.h> 
int main()
{
   int array_first[2][2]={{1,2},{3,4}};
   int array_second[2][2]={{1,2},{3,4}};
   int array_third[2][2];
   int i,j;  
   printf("First array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array_first[i][j]);
}
printf("\n");
}
printf("Second array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array_second[i][j]);
}
printf("\n");
}
printf("Addition of First and Second array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    array_third[i][j]=array_first[i][j]+array_second[i][j];
    printf("%d ",array_third[i][j]);
}
printf("\n");
}
}

•Output 

First array is given below 
1 2
3 4
Second array is given below 
1 2
3 4
Addition of First and Second array is given below
2 4
6 8

    5.SUBTRACTION OF DOUBLE DIMENSION                               ARRAY: 

#include<stdio.h> 
int main()
{
   int array_first[2][2]={{6,7},{8,9}};
   int array_second[2][2]={{1,2},{3,4}};
   int array_third[2][2];
   int i,j;  
   printf("First array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array_first[i][j]);
}
printf("\n");
}
printf("Second array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array_second[i][j]);
}
printf("\n");
}
printf("Sutraction of First and Second array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    array_third[i][j]=array_first[i][j]-array_second[i][j];
    printf("%d ",array_third[i][j]);
}
printf("\n");
}
}

•Output 

First array is given below 
6 7
8 9
Second array is given below 
1 2
3 4
Addition of First and Second array is given below
5 5
5 5

 6.MULTIPLICATION OF DOUBLE DIMENSION                                ARRAY: 

#include<stdio.h> 
int main()
{
   int array_first[2][2]={{1,2},{3,4}};
   int array_second[2][2]={{1,2},{3,4}};
   int array_third[2][2];
   int i,j,k,sum;  
   
   printf("First array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array_first[i][j]);
}
printf("\n");
}
printf("Second array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array_second[i][j]);
}
printf("\n");
}
printf("Multiplication of First and Second array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    sum=0;
    for(k=0;k<=1;k++)
    {
    sum=sum+array_first[i][k]*array_second[k][j];
    }
    array_third[i][j]=sum;
    printf("%d ",array_third[i][j]);
}
printf("\n");
}
}

•Output 

First array is given below 
1 2
3 4
Second array is given below 
1 2
3 4
Addition of First and Second array is given below
 7  10
15 22

      7.TRANSPOSE OF DOUBLE DIMENSION                                  ARRAY: 

#include<stdio.h> 
int main()
{
   int array[2][2]={{5,5},{9,9}};
   int i,j;
   printf("Array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array[i][j]);
}
printf("\n");
}
printf("Transpose of Array is given below\n");
    for(i=0;i<=1;i++)
    {
    for(j=0;j<=1;j++)
    {
    printf("%d ",array[j][i]);
}
printf("\n");
}
}

•Output 

Array is given below 
5 5
9 9
Transpose of array is given below 
5 9
5 9

Comments

Popular posts from this blog

Java vs C++

STRUCTURE

SWITCH PROGRAMME