求“小九九”程序

wwwhh 2003-05-15 02:47:13
c语言
...全文
64 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
murderer 2003-05-21
  • 打赏
  • 举报
回复
TC3下编译通过,TC2下应该也没问题。

#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphics.h>

#define BKCOLOR 9
#define TEXTCOLOR 1
#define FOCUSCOLOR 14
#define UPCOLOR 15
#define DOWNCOLOR 7

void display();
void drawCaption(const char*, int, int, int, int, int = TEXTCOLOR);
void drawLeftUp(int, int, int, int, int = TEXTCOLOR);
void drawRightDown(int, int, int, int, int = TEXTCOLOR);
void drawTable(int, int, int, int, int, int, int = TEXTCOLOR);
void fillTable(int, int);

int main()
{

int gdriver = DETECT, gmode;

initgraph(&gdriver, &gmode, "");

int errorcode;
errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}

display();
closegraph();
return 0;
}

void display()
{
int x1 = 0, x2 = x1 + 300;
int y1 = 0, y2 = y1 + 200;
int i = 0;
for (; i < 16; ++i)
{
setfillstyle(SOLID_FILL, i);
bar(x1, y1, x2, y2);
drawTable(x1, y1+20, x2, y2, 10, 10);
drawLeftUp(x1, y1, x2, y2);
drawRightDown(x1, y1, x2, y2);
drawCaption("Multiple Table", x1, 0, x2, 20);
delay(1500);
}

return ;
}

void drawCaption(const char* buf, int x1, int y1, int x2, int y2, int color)
{
int tempColor = color;
int len = strlen(buf) * 8;
setcolor(BKCOLOR);
bar(x1, y1, x2, y2);
drawLeftUp(x1, y1, x2, y2);
drawRightDown(x1, y1, x2, y2);
drawLeftUp(x1, y2, x2, y2);

setcolor(0);
outtextxy(x1+8, y1+8, buf);

setcolor(FOCUSCOLOR);
outtextxy(x1+5, y1+5, buf);

setcolor(0);
line (x1+len+10, y1+7, x2-1, y1+7);
line (x1+len+10, y1+14, x2-1, y1+14);

setcolor(FOCUSCOLOR);
line (x1+len+10, y1+6, x2-1, y1+6);
line (x1+len+10, y1+13, x2-1, y1+13);

setcolor(tempColor);
}

void drawLeftUp(int x1, int y1, int x2, int y2, int color)
{
int tempColor = color;
setcolor(UPCOLOR);
line (x1, y1, x2, y1);
line (x1, y1, x1, y2);
setcolor(tempColor);
}

void drawRightDown(int x1, int y1, int x2, int y2, int color)
{
int tempColor = color;
setcolor(DOWNCOLOR);
line (x2, y1, x2, y2);
line (x1, y2, x2, y2);
setcolor(tempColor);
}

void drawTable(int x1, int y1, int x2, int y2, int Col, int Line, int color)
{
int tempColor = color;
int cellX = (x2 - x1) / Col;
int cellY = (y2 - y1) / Line;
int i = 1, j = 1;
int temp = 0;

setcolor(DOWNCOLOR);
for (i = 1; i < Col; ++i)
{
temp = i * cellX + x1;
line (temp, y1, temp, y2);
}
for (j = 1; j < Line; ++j)
{
temp = j * cellY + y1;
line (x1, temp, x2, temp);
}
setcolor (TEXTCOLOR);
fillTable (cellX, cellY);
setcolor (tempColor);
}

void fillTable(int cX, int cY)
{
int i = 1, j = 1;
int y = 0;
char buf[8];
for (j = 1; j < 10; ++j)
{
y = 20 + j*cY + (cY-8)/2;
for (i = 1; i < 10; ++i)
{
sprintf(buf, "%d", i * j);
outtextxy(i*cX + (cX-8)/2, y, buf);
}
}
for (i = 1; i < 10; ++i)
{
sprintf(buf, "%d", i);
outtextxy(i*cX + (cX-8)/2, 20 + (cY-8)/2, buf);
}
for (j = 1; j < 10; ++j)
{
sprintf(buf, "%d", j);
outtextxy(10, j*cY + 20 + (cY-8)/2, buf);
}
}
song0542 2003-05-20
  • 打赏
  • 举报
回复
#include "stdio.h"
void main()
{
int i
int j
for(i = 1; i <=9; i++)
{
for(j = 1; j <= i; j++)
{

printf("%d * %d = %d ", j, i, j*i);
}
putchar('/n');
}
}
98440622 2003-05-15
  • 打赏
  • 举报
回复
TC2.0版
#include "stdio.h"
void main()
{
for(int i = 9; i > 0; i--)
{
for(int j = 1; j <= i; j++)
{

printf("%d * %d = %d", j, i, j*i);
}
putchar('/n');
}
}
snipersu 2003-05-15
  • 打赏
  • 举报
回复
//one more
#include<iostream.h>
void main()
{
for(int i=9;i>0;i--)
{
for(int j=1;j<=i;j++)
{
cout<<j<<"*";
cout<<i<<"="<<i*j<<" ";
}
cout<<endl;
}
}
snipersu 2003-05-15
  • 打赏
  • 举报
回复
#include<iostream.h>
void main()
{
for(int i=1;i<10;i++)
{
for(int j=1;j<=i;j++)
{
cout<<j<<"*";
cout<<i<<"="<<i*j<<" ";
}
cout<<endl;
}
}

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧