- 1、本文档共111页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C语言必背个程序+例--语法高亮.doc
C语言必背18个经典程序
输入什么显示什么
main()
{
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
}
可以在Win-tc下编译通过
C语言精彩作图之一颗三维的心
/* Heart */
#include graphics.h
#include math.h
#define PI 3.1415926
void main()
{
double a;
int x,y,y1,r,r1;
int gdriver=DETECT,gmode;
initgraph(gdriver,gmode,c:\\tc);
printf(Please input Radus(80): );
scanf(%d,r);
cleardevice();
setbkcolor(9);
setcolor(4);
outtextxy(80,20,This program show the Heart picture.);
y1=240-r;
for(a=0;a=2*PI;a+=PI/27)
{ x=320+r*cos(a);
y=240+r*sin(a);
r1=sqrt((x-320)*(x-320)+(y-y1)*(y-y1));
circle(x,y,r1);
}
outtextxy(80,460,Press any key to quit...);
getch();
closegraph();
}
用C语言显示BMP图形
#include stdio.h
#include dir.h
#include dos.h
#include graphics.h
char *malloc();/*malloc转换*/
char bmp_to_dat(char *bmp,char *dat)
/*将16色BMP文件转换为可以用putimage输出的格式,bmp为原BMP文件,dat为转化文件*/
{
unsigned char c[8],scan_times,scan_pixs;
unsigned char workpos;int i,j,k,n,nowpos,iw,ih;
static int color[16]={0,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15};
unsigned char workline[640],scanline[640];
FILE *fp,*targetfp;
union
{
unsigned char value;
struct
{
unsigned cl:4;
unsigned ch:4;
}color;
}mycolor;
if((fp=fopen(bmp,rb))==NULL)return(0);
targetfp=fopen(dat,wb);
fseek(fp,18,SEEK_SET);
iw=0;ih=0;
fread(iw,4,1,fp); /*读图像宽度*/
fread(ih,4,1,fp); /*读图像高度*/
if(iw==0ih==0iw640ih480)
{fclose(fp);fclose(targetfp);return(0);}
iw--;ih--; /*∵putimage中的长宽比实际数值少1*/
scan_times=iw/8+1; /*行处理单位数*/
scan_pixs=scan_times*4; /*行像素字节数∵1单位=4字节*/
fputc(iw%256,targetfp); /*填充信息头:长、宽部分*/
fputc(iw/256,targetfp);
fputc(ih%256,targetfp);
fputc(ih/256,targetfp);
fseek(fp,-scan_pixs,SEEK_END)
文档评论(0)