/* Wap to read and print a matrix or array of size r x c. */
#include < stdio.h >
main()
{
int a[5][5],r,c,i,j;
printf("\nEnter the order for matrix ");
scanf("%d%d",&r,&c);
printf("\nEnter the element for array");
for( i=0 ; i < r; i++)
{
for( j=0 ; j < c; j++)
{
scanf("%d" , &a[i][j] );
}
}
printf("\nElements of array are \n");
for( i=0 ; i < r; i++)
{
for( j=0 ; j < c; j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
}
Description:
The above program declares the array by name 'a' of maximum size 5 x 5, r and c variables are used to indicate the number of rows and columns, i and j are index variable to represent the current row and column in looping statements.
After the declaration the value for r and c will be read. The first for loop is for accepting array elements from user. Second for loop is for printing array elements in a matrix format.
#include < stdio.h >
main()
{
int a[5][5],r,c,i,j;
printf("\nEnter the order for matrix ");
scanf("%d%d",&r,&c);
printf("\nEnter the element for array");
for( i=0 ; i
for( j=0 ; j
scanf("%d" , &a[i][j] );
}
}
printf("\nElements of array are \n");
{
for( j=0 ; j < c; j++)
printf("%3d",a[i][j]);
}
printf("\n");
}
}
Description:
The above program declares the array by name 'a' of maximum size 5 x 5, r and c variables are used to indicate the number of rows and columns, i and j are index variable to represent the current row and column in looping statements.
After the declaration the value for r and c will be read. The first for loop is for accepting array elements from user. Second for loop is for printing array elements in a matrix format.
Comments
Post a Comment