**
二维数组的简单输出
**
代码:
#include<stdio.h>
int main()
{
int i,j,a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%3d",a[i][j]);
printf("\n");
}
return 0;
}
输出结果:
1 2 3
4 5 6
7 8 9
--------------------------------
Process exited with return value 0
Press any key to continue . . .
**
gets()函数的运用
**
用法:输入一个字符串到数组
代码:
#include<stdio.h>
int main()
{
char str[80];
gets(str);
printf("%s",str);
return 0;
}
输出结果1:
abcdef
abcdef
--------------------------------
Process exited with return value 0
Press any key to continue . . .
输出结果2:
abc def
abc def
--------------------------------
Process exited with return value 0
Press any key to continue . . .
结论:gets函数能自由的在字符串中加入空格
**
puts函数的用法:
**
用法:输出一个字符串
代码:
#include<stdio.h>
int main()
{
int i;
char str[]={"abcdef"};
for(i=1;i<=3;i++)
{
puts(str);
}
return 0;
}
输出结果:
abcdef
abcdef
abcdef
--------------------------------
Process exited with return value 0
Press any key to continue . . .
结论:puts()函数能自动换行
这篇博客介绍了C语言中二维数组的简单输出方法,通过一个3x3的矩阵展示了如何遍历并打印数组元素。同时,文章探讨了gets()函数的使用,展示其能接收带有空格的字符串输入。最后,讲解了puts()函数的功能,它能够方便地输出字符串并自动换行。这些基础知识对于C语言初学者至关重要。

2962

被折叠的 条评论
为什么被折叠?



