本题一个完整的c程序如下,程序在tc2.0和win-tc下运行通过,结果正确。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main()
{float pi=3.14159265,r
textbackground(YELLOW)/* 设置背景色为黄色,注意颜色应该大写,可更改 */
textcolor(RED)/* 设置文件颜色为红色,可更改 */
clrscr()/* 清屏,使设置生效 */
printf("enter radius:"差此戚)
scanf("%f",&r)
if(r<0)
printf("Enter Error!\n")
else
printf("r=%.2f,c=%.2f,area=%.2f\n",r,2*pi*r,pi*r*r)
system("pause")/* 暂停,按任一键虚陵继续 */
}
---------------------------------------------------------------------
---------------------------------------------------------------------
以下仅供参考。可以连续输入8次,每次得到的颜色不同,当然可以改变for (color = 0color <8color++)中color<8的数值来控制输出的颜色数。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
{float pi=3.14159265,r
int color
for (color = 0color <8color++)
{
textbackground(color)
cprintf("This is color %d\r\n", color)
cprintf("enter radius:")
scanf("%f",&r)
if(r<0)
cprintf("Enter Error!\r\n")
else
cprintf("r=%.2f,c=%.2f,area=%.2f\r\n",r,2*pi*r,pi*r*r)
cprintf("Press any key to continue\r\n"扒判)
getch()
}
system("pause")
}
你可以参阅:
http://zhidao.baidu.com/question/86663727.html
http://zhidao.baidu.com/question/79605706.html
http://zhidao.baidu.com/question/79605348.html
#include<stdio.h>
#include<time.h>
#include<windows.h>
typedef struct
{
int x,y
char ch
}STU
STU st[100]
//出现位置
void gotoxy(int x, int y)
{
HANDLE hout
COORD pos
pos.X = x
pos.Y = y
hout = GetStdHandle(STD_OUTPUT_HANDLE)
SetConsoleCursorPosition(hout, pos)
}
/*隐藏光标*/
void show_cursor(int hide)
{
CONSOLE_CURSOR_INFO cciCursor
HANDLE hout
hout = GetStdHandle(STD_OUTPUT_HANDLE)
if(GetConsoleCursorInfo(hout, &cciCursor))
{
cciCursor.bVisible = hide
SetConsoleCursorInfo(hout, &cciCursor)
}
}
/*设置颜色*/
void set_color(int color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color)
}
main()
{
int i,j
show_cursor(0)
srand(time(NULL))
//初始化结构体
for (i=0i<100i++)
{
st[i].x = rand()%80
st[i].y = rand()%20
st[i].ch = rand()%(49-47)+48
}
while (1)
{
for (i=0i<档尘100i++)
{
gotoxy(st[i].x,st[i].y)
set_color(0x2)//最先出现的颜色;
putchar(st[i].ch)
gotoxy(st[i].x,st[i].y-5)
putchar(' ')
st[i].y++
st[i].ch = rand()%(49-47)+48
if (st[i].y-5>=18)
{
gotoxy(st[i].x,st[i].y-1)
putchar(' ')
gotoxy(st[i].x,st[i].y-2)
putchar(' ')
gotoxy(st[i].x,st[i].y-3)
putchar(' ')
gotoxy(st[i].x,st[i].y-4)
putchar(' ')
gotoxy(st[i].x,st[i].y-4)
putchar(' ')
}
if (st[i].y >23)
{
st[i].x = rand()%80
st[i].y = rand()%20
}
gotoxy(st[i].x,st[i].y)
set_color(0xA)//由前一个颜色渐变成的颜色
putchar(st[i].ch)
}
Sleep(120)
}
}
color(0) printf("黑色\n") color(1) printf("蓝色\n") color(2) printf("绿色\n") color(3) printf("湖蓝色\n") color(4) printf("红色\n") color(5) printf("紫色\n") color(6) printf("黄色\n") 漏蠢歼 color(7) printf("白色\n") color(8) printf("灰色\n") color(9) printf("淡蓝色\n") color(10) printf("淡绿色\n") color(11) printf("淡浅绿色\n") 返冲 color(12) printf("淡红色\n") color(13) printf("淡紫色\n") color(14) printf("淡黄色\n") color(15) printf("亮白色\n")几个基本的颜色;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)