本文介绍了C程序输入数组[3] [3] = {1,2,3,4,5,6,7,8,9}打印输出如下= 1,2,35,5输入数组[3] [3 ] = {1,2,3,4,5,6,7,8,9}打印输出如:1,2,3,6,5,4,7,8,9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C程序输入数组[3] [3] = {1,2,3,4,5,6,7,8,9}

打印输出如下= 1,2, 36,5,



输入数组[3] [3] = {1,2,3,4,5,6,7,8,9}

打印输出喜欢:1,2,3,6,5,4,7,8,9



我试过的:



C program input array[3][3] = {1,2,3,4,5,6,7,8,9}
print output like this = 1,2,36,5,

input array[3][3] = {1,2,3,4,5,6,7,8,9}
print output Like : 1,2,3,6,5,4,7,8,9

What I have tried:

int main()
{
	int array[3][3];
	int i,j;
	printf("Enter the elements of the array:\n");
	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			scanf("%d",&array[i][j]);

	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			printf(" %d",array[i][j]);

	return 0;

}

推荐答案

for(i=0;i<3;i++)
{
    for(j=0;j<3;j++)
    {
        /* Print comma and space if not first element */
        if (i || j)
            printf(", ");
        printf("%d",array[i][j]);
    }
}
printf("\n");


这篇关于C程序输入数组[3] [3] = {1,2,3,4,5,6,7,8,9}打印输出如下= 1,2,35,5输入数组[3] [3 ] = {1,2,3,4,5,6,7,8,9}打印输出如:1,2,3,6,5,4,7,8,9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 20:00