Author
Yan Xiaolin
Working during the day and dreaming at night. I have stories, do you have any wine?
Array a sequence:
1 2 3
4 5 6
Array b sequence:
1 4
2 5
3 6
#include<stdio.h>// Header file
int main()// Main function
{
int i,j;// Define integer variables
int a[2][3]={{1,2,3},{4,5,6}};// Define a two-dimensional array and assign initial values
int b[3][2];// Define another two-dimensional array
printf("Horizontal array sequence:\n");// Prompt statement
for(i=0;i<2;i++)// Outer for loop, limiting rows, total 2 rows
{
for(j=0;j<3;j++)// Inner for loop, limiting columns, total 3 columns
{
printf("%6d",a[i][j]);// Output array element value, width 6
b[j][i]=a[i][j];// Assign value
}
printf("\n");// New line
}
printf("Vertical array sequence:\n");// Prompt statement
for(i=0;i<3;i++)// Outer for loop, limiting rows, total 3 rows
{
for(j=0;j<2;j++)// Inner for loop, limiting columns, total 2 columns
{
printf("%6d",b[i][j]);// Output array element value, width 6
}
printf("\n");// New line
}
return 0;// Function return value is 0
}
Horizontal array sequence:
1 2 3
4 5 6
Vertical array sequence:
1 4
2 5
3 6
--------------------------------
Process exited after 0.04857 seconds with return value 0
Press any key to continue...
Follow the official account below, reply with 1, and you’ll be added for free to a programming community of 15,000 people, plus receive 100 C language source code cases, including Snake, Tetris, heart-shaped confession, and Christmas tree source code~