C语言设计出来的程序 的背景颜色怎样通过代码控制?

下面给一个简单的程序, 给这个程序加上以下代码 ,只要能把颜色改变。
把改变厚的代码写在下面 要把改变颜色的代码与我上面的代码结合起来,然后我会当场输入编译器 查看 是否有效! 在网上看了很多资料都无法改变颜色 才想了这个办法。

#include<stdio.h>
main()
{float pi=3.14159265,r;
printf("enter radius:\n");
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");
}
最好留下联系方式(q),那样我会优先采纳。 前面四位我都试了 不行,给出答案以前一定要自己先试验一下。达到背景黑色变成其他颜色,字体颜色随便

system("COLOR 17"); // DOS 窗 背景兰色字白色 

system("COLOR 34"); // DOS 窗 背景淡兰色字红色 

自己尝试尝试,就会发现很多种颜色的组合的 

这么做: 

#include<stdio.h> 

#include<stdlib.h> 

main() 

{float pi=3.14159265,r; 

//system("COLOR 17"); // DOS 窗 背景兰色字白色 

system("COLOR 34"); // DOS 窗 背景淡兰色字红色 

printf("enter radius:\n"); 

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"); 

}

//给出答案以前一定要自己先试验一下。达到背景黑色变成其他颜色,字体颜色随便

说别人的答案不对之前,自己最好先确认一下自己的编译器设置之类的是不是正确,这么多人的都不对,你不觉得应该先找找自己的原因?

下面的图是我的代码的运行结果,

编译器VC6.0

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-28
已经按你的要求重新改写,简化。
本题一个完整的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 = 0; color < 8; color++)中color<8的数值来控制输出的颜色数。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
{float pi=3.14159265,r;
int color;
for (color = 0; color < 8; color++)
{
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本回答被提问者采纳
第2个回答  2009-02-19
你是要做 Windows 下面做吗?
以前我有做过,你去 msdn 上查查怎么控制命令行下的字体和颜色就知道了。
第3个回答  2009-02-19
#include<stdio.h>
#include<stdlib.h>
void main()
{float pi=3.14159265,r;
system("color F0");
printf("enter radius:\n");
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");
}

你要的是这种效果?