大表格

<html>
<head>
<title>表格</title>
</head>
<body>
<center>大表格</center>
<table border="1" width="700" height="700" align="center">
<tr>
<td colspan="6" bgcolor="red"></td>
<td rowspan="6" bgcolor="green"></td>
</tr>
<tr>
<td rowspan="6" bgcolor="black"></td>
<td colspan="4" bgcolor="yellow"></td>
<td rowspan="4" bgcolor="pink"></td>
</tr>
<tr>
<td rowspan="4" bgcolor="#990033"></td>
<td colspan="2" bgcolor="#993300"></td>
<td rowspan="2" bgcolor="#660033"></td>
</tr>
<tr>
<td rowspan="2" bgcolor="#000099"></td>
<td bgcolor="#66ff33"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#660000"></td>
</tr>
<tr>
<td colspan="4" bgcolor="#ff3300"></td>
</tr>
<tr>
<td colspan="6" bgcolor="#993300"></td>
</tr>
</table>
</body>
</html>
在C语言中实现打印表格可以有多种方式,下面结合引用中的示例来介绍。 ### 实现舒尔特表格打印 引用[2]给出了一个通过代码实现2*2到100*100之内的舒尔特表格的例子,该表格每个表随机产生20组,既可以打印输出,也可以生成文件方便拷贝到Word中打印。以下是该示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <time.h> int main() { int j = 0,number = 0,n = 0,count=1,counter = 0; int a[10000]={0}; char buff[64]; FILE* fp; printf("输入舒尔特表格行数(≤100):"); scanf("%d",&n); srand((unsigned) time(NULL)); memset(buff, 0, sizeof(buff)); counter = 10; sprintf(buff,"Schulte_Grid_%dx%d.txt",n,n); fp = fopen(buff, "w+"); for(j=0; j<counter; j++) { while(count<=n*n) { number= rand()%(n*n); if(a[number]==0) { a[number]=count; count++; } } for(count=0;count<n*n;count++) { if(count%n==0) { printf("\n"); fprintf(fp,"\n"); } printf("%4d ",a[count]); fprintf(fp,"%8d ",a[count]); } fflush(fp); count=1; memset(a, 0, sizeof(a)); fprintf(fp,"\n"); } fclose(fp); return 0; } ``` 在这个示例中,通过`printf`函数在控制台打印表格内容,同时使用`fprintf`函数将表格内容写入文件。 ### 基本表格打印示例 下面是一个简单的基本表格打印示例,用于打印一个3行3列的表格: ```c #include <stdio.h> int main() { int rows = 3; int cols = 3; int table[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; // 打印表头 for (int i = 0; i < cols; i++) { printf("Column %d\t", i + 1); } printf("\n"); // 打印分隔线 for (int i = 0; i < cols; i++) { printf("--------\t"); } printf("\n"); // 打印表格内容 for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { printf("%d\t", table[i][j]); } printf("\n"); } return 0; } ``` 这个示例定义了一个二维数组来表示表格数据,然后使用嵌套的`for`循环遍历数组并打印表格内容,同时添加了表头和分隔线来使表格更美观。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值