0:
#include <stdio.h>
int main()
{
int a[4][5] = {
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20}};
int i,j;
for (i = 0; i < 4; i++){
for (j = 0; j < 5; j++){
printf("%-5d ",a[i][j]);
if ( i + j == 3){
printf("\n");
}
}
}
printf("\n");
return 0;
}
1:
#include <stdio.h>
#define M 2
#define N 2
#define P 3
int main()
{
int a[M][P] = {
{1, 2, 3},
{4, 5, 6}};
int b[P][N] = {
{1, 4},
{2, 5},
{3, 6}};
int c[M][N] = {0};
int i, j, k, row;
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
{
for (k = 0; k < P; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
// row 取行数最大值
row = M > P ? M : P;
for (i = 0; i < row; i++)
{
// 打印A
printf("| ");
for (j = 0; j < P; j++)
{
if (i < M)
{
printf("\b%d ", a[i][j]);
printf("|");
}
else
{
printf("\b\b\b ");
}
}
// 打印 * 号
if (i == row / 2)
{
printf(" * ");
}
else
{
printf(" ");
}
printf("| ");
// 打印B
for (j = 0; j < N; j++)
{
if (i < P)
{
printf("\b%d ", b[i][j]);
printf("|");
}
else
{
printf("\b\b\b ");
}
}
// 打印 = 号
if (i == row / 2)
{
printf(" = ");
}
else
{
printf(" ");
}
// 打印C
printf("| ");
for (j = 0; j < N; j++)
{
if (i < M)
{
printf("\b%d ", c[i][j]);
printf("|");
}
else
{
printf("\b\b\b ");
}
}
printf("\n");
}
return 0;
}
2:
#include <stdio.h>
#include <string.h>
int main()
{
char slogan[5][100];
int i;
int j;
int length,finall,slow,last;
length = 0;
finall = 0;
last = 0;
slow = 0;
for (i = 0; i < 5; i++){
j = i + 1;
printf("请输入第%d句话:",j);
gets(slogan[i]);
}
printf("你输入了下边这些话:\n");
for ( i = 0; i < 5; i++){
printf("%s\n",slogan[i]);
}
for ( i = 0; i < 5; i++){
if (strlen(slogan[i]) > length){
length = strlen(slogan[i]);
slow = length;
finall = i;
}
if (strlen(slogan[i]) < slow){
slow = strlen(slogan[i]);
last = i;
}
}
printf("其中最长的是%s\n",slogan[finall]);
printf("其中最短的是:%s\n",slogan[last]);
return 0;
}