C语言入门到入魔经典案例
C语言入门到入魔经典案例
编程与实战
这个作者很懒,什么都没留下…
展开
-
152.利用图形页实现动画
#include <graphics.h>#include <stdio.h>#include <stdlib.h>#include <alloc.h>#include <math.h>void main(){ void * ptr; int gd=9,gm=2; float i; /*registerbgidriver(EGAVGA_driver);*/ initgraph(&gd,&gm,".原创 2022-05-09 14:46:51 · 1451 阅读 · 1 评论 -
151.动态显示位图
#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 w.原创 2022-05-09 14:45:55 · 1403 阅读 · 0 评论 -
150.运动的小车动画
#include<time.h>#include<stdlib.h>#include<graphics.h>#include<conio.h>#include<dos.h>#include<math.h>#define step 10#define R 10main(){ int gdriver=9,gmode=2; static int startx=5; static int starty=100; .原创 2022-05-09 14:44:56 · 1734 阅读 · 0 评论 -
149.屏幕检测程序
#include <stdio.h>#include <dos.h>#include <graphics.h>#include <conio.h>#include <stdlib.h>#define INTR 0x1cvoid interrupt ( *oldhandler) ();int fre[]={523,659,587,659,587,494,587,523,440,440,440,330,392,440,494,494,.原创 2022-05-09 14:43:51 · 1573 阅读 · 0 评论 -
148.绘制蓝天图案
#include <stdio.h>#include <dos.h>#include <math.h>long Addr[768];int Mode;Set_Mode (int mode) /*设置显示的模式,参数为INT 10H的子功能号*/{ union REGS r; r.h.ah=0; r.h.al=mode; int86 (0x10,&r,&r);}Set_Graphics_Mode (uns.原创 2022-05-09 14:42:46 · 1355 阅读 · 0 评论 -
147.VGA256色模式编程
/* VGA256.c -- VGA 256 色编程*/#include "dos.h"#include "conio.h"#include "stdio.h"void InitScr();void RstScr();void PutPoint(int x, int y, int Color);void Rect(int x1, int y1, int x2, int y2, int Color);void LineV(int x1, int y1, int x2, int .原创 2022-05-09 14:37:20 · 1538 阅读 · 0 评论 -
146.矩形区域的颜色填充
#include <stdio.h>#include <graphics.h>void main(){int gd=VGA,gm=VGALO; /*registerbgidriver(EGAVGA_driver);*/ initgraph(&gd,&gm,"e:\\tc\\bgi"); /*设置图形模式*/ setcolor(YELLOW); rectangle(105,105,175,135); /*画正方形*/ full(120,120,YEL.原创 2022-05-09 14:36:32 · 2112 阅读 · 0 评论 -
145.艺术清屏
#include<stdio.h>#include<dos.h>#include<conio.h>void goto_xy(int x,int y);void dcls(int x1,int x2,int y1,int y2);void bcls(int x1,int x2,int y1,int y2);void recls(int x1,int x2,int y1,int y2);void zcls(int x1,int x2,int y1,int y.原创 2022-05-09 14:33:57 · 1344 阅读 · 0 评论 -
144.绘制布朗运动曲线
/* 一维布朗运动曲线 *//* 本程序利用分形技术画一维的布朗运动曲线 *//* BC 3.1编译 *//* 其中函数initgraph的第三个参数可能需要修改 */#include "graphics.h"#include "math.h"#include "stdlib.h"#include "conio.h"#include "time.h"#include "stdio.h"#define MAX_SIZE 1.原创 2022-05-09 14:33:04 · 1542 阅读 · 0 评论 -
143.Mandelbrot分形图案
/*原理:1. 使用叠代公式: z[0] = zInit; z[k] = z[k-1]*z[k-1] + z[0]其中z[i]是复数,要使用复数的运算法则。2. Mandelbort图形集的初始化要求 -2.25<= Re(zInit) <= 0.75 -1.25<= Im(zInit) <= 1.25 其中Re(z)表示z的实部, Im(z)表示z的虚部*/#include <graphics.h>typedef .原创 2022-05-09 14:28:45 · 1625 阅读 · 0 评论 -
142.抛物样条曲线
/* draw Parspl */#include <graphics.h>#include <math.h>#include <stdio.h>void parspl(p,n,k,e)int p[][2],n,k,e;{ int x,y,i,j,m; float t1,t2,t3,t,a,b,c,d; if(e==1) { m=n; p[0][0]=p[1][0]; p[0][1]=p[1][1]; p[n+1][0]=p[n][.原创 2022-05-09 14:27:47 · 1424 阅读 · 0 评论 -
141.图形法绘制椭圆
#include <graphics.h>#include <math.h>void ellipse1(x0,y0,a,b,dt)int x0,y0,a,b,dt;{ int x,y,n,i; float t1,t=0.0; t1=dt*0.0174533; n=360/dt; moveto(x0+a,y0); for(i=1;i<n;i++) { t=t+t1; x=x0+a*cos(t); y=y0+b*sin(t); lineto(.原创 2022-05-09 14:26:31 · 1481 阅读 · 0 评论 -
140.递归法绘制三角形图案
#include <graphics.h>#include <stdio.h>void tria(xa,ya,xb,yb,xc,yc,n)int xa,ya,xb,yb,xc,yc,n;{ int xp,yp,xq,yq,xr,yr; if(n>0) { xp=(xa+xb)/2; yp=(ya+yb)/2; xq=(xb+xc)/2; yq=(yb+yc)/2; xr=(xc+xa)/2; yr=(yc+ya)/2; moveto(.原创 2022-05-09 14:25:37 · 1979 阅读 · 0 评论 -
139.图形法绘制圆
#include <stdio.h>#include <graphics.h>#include <dos.h>/*这是根据给出的圆心坐标和点坐标分别在八个象限画点的子程序*/void circlePoint( int xCenter, int yCenter, int x, int y ){ putpixel( xCenter + x, yCenter + y, YELLOW ); putpixel( xCenter - x, yCenter + y, Y.原创 2022-05-09 14:24:39 · 1412 阅读 · 0 评论 -
138.正方形螺旋拼块图案
#include <graphics.h>#include <math.h>void polygonc();void block();void main(){ int i,j,a,length,n,theta,x=100,y=350; int gdriver=DETECT,gmode; printf("input length, n theta:"); scanf("%d%d%d",&length,&n,&theta); initgra.原创 2022-05-09 14:21:20 · 1370 阅读 · 0 评论 -
137.正六边形螺旋图案
#include <graphics.h>#include <math.h>void polygonc();void main(){ int i,r,n,x=320,y=240; int gdriver=9,gmode=2; float theta,alfa; n=30; theta=6.0; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setbkcolor(MAGENTA); s.原创 2022-05-09 14:18:58 · 1622 阅读 · 0 评论 -
136.绘制正多边形
#include <graphics.h>#include <math.h>void polygon(x0,y0,a,n,af)int x0,y0,a,n;float af;{ int x,y,i; float dtheta,theta; if(n<3) return; dtheta=6.28318/n; theta=af*0.0174533; moveto(x0,y0); x=x0; y=y0; for(i=0;i<n;i++) {.原创 2022-05-09 14:14:59 · 1575 阅读 · 0 评论 -
135.设置图形方式下的文本类型
/* text */#include <graphics.h>#include <dos.h>void main(){ int i,t,x=300,y=50; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); setbkcolor(9); setcolor(4); printf("Please input delay time (1-10): "); scanf("%d.原创 2022-05-09 14:14:05 · 1318 阅读 · 0 评论 -
134.沙丘图案
/* Sandhill */#include <graphics.h>#include <math.h>#define PI 3.1415926void main(){ double a,b,c; int x,y,py; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setbkcolor(9); setcolor(14); outt.原创 2022-05-09 14:13:19 · 1376 阅读 · 0 评论 -
133.渔网图案
/* Fishing Net */#include <graphics.h>void main(){ int x,y,x1,y1,x0=320,y0=50; int i,j,n=5,r=20; int gdriver=VGA,gmode=VGAHI; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setbkcolor(9); outtextxy(80,20,"This program show the.原创 2022-05-08 22:17:26 · 1456 阅读 · 0 评论 -
132.心脏形图案
/* Heart */#include <graphics.h>#include <math.h>#define PI 3.1415926void 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",&.原创 2022-05-08 22:16:39 · 1329 阅读 · 0 评论 -
131.肾形图案
/* Kidney */#include <graphics.h>#include <math.h>#define PI 3.1415926void main(){ double a; int x,y,r,r1; int gdriver=9,gmode=2; initgraph(&gdriver,&gmode,"c:\\tc"); printf("Please input Radus(<150): "); scanf("%d",&.原创 2022-05-08 22:15:50 · 1488 阅读 · 0 评论 -
130.圆环图案
/* circles */#include <graphics.h>#include <math.h>#define PI 3.1415926void main(){ double a; int x,y,r1,rs; int gdriver=DETECT,gmode; printf("Please input R1(<100) and Rs:\n"); scanf("%d%d",&r1,&rs); initgraph(&gdri.原创 2022-05-08 22:15:12 · 1772 阅读 · 0 评论 -
129.飘带图案
/* linesin */#include <graphics.h>#include <math.h>#define PI 3.1415926void main(){ double a; int x1,y1,x2,px=320,py=240; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setcolor(4); outtextxy(.原创 2022-05-08 22:14:33 · 1346 阅读 · 0 评论 -
128.金刚石图案
/* diamond */#include <graphics.h>#include <math.h>void main(){ float t; int x0=320,y0=240; int n,i,j,r; int x[50],y[50]; int gdriver=DETECT,gmode; printf("Please input n(23<=n<=31) and r(100<=r<=200):\n"); scanf("%d%d",.原创 2022-05-08 22:13:37 · 1394 阅读 · 0 评论 -
127.图形文本的输出
/* line */#include <graphics.h>void main(){ int x; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setcolor(4); for(x=160;x<=480;x+=20) { line(160,240,x,120); line(160,240,x,360); line(480,24.原创 2022-05-08 22:12:55 · 1403 阅读 · 0 评论 -
126.设置填充类型和填充颜色
/* set fill style */#include <graphics.h>void main(){ int i,c=4,x=5,y=6; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setcolor(c); for(i=c;i<c+8;i++) { setcolor(i); rectangle(x,y,x+140,y+104.原创 2022-05-08 22:03:06 · 1393 阅读 · 0 评论 -
125.设置线条类型
/* set line style */#include <graphics.h>void main(){ int i,j,c,x=50,y=50,k=1; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setbkcolor(9); setcolor(4); for(j=1;j<=2;j++) { for(i=0;i<4;i++).原创 2022-05-08 22:01:33 · 1309 阅读 · 0 评论 -
124.设置背景色和前景色
/* set color */#include <graphics.h>void main(){ int cb,cf; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); for(cb=0;cb<=15;cb++) { setbkcolor(cb); for(cf=0;cf<=15;cf++) { setcolor(cf); .原创 2022-05-08 21:59:15 · 1917 阅读 · 0 评论 -
123.绘制椭圆
#include <graphics.h>void main(){ int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); moveto(160,120); linerel(320,0); linerel(0,240); linerel(-320,0); linerel(0,-240); getch(); closegraph();}原创 2022-05-08 21:55:22 · 1521 阅读 · 0 评论 -
122.绘制圆弧
#include <graphics.h>void main(){ int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); moveto(160,120); linerel(320,0); linerel(0,240); linerel(-320,0); linerel(0,-240); getch(); closegraph();}原创 2022-05-08 21:54:28 · 1537 阅读 · 0 评论 -
121.绘制圆
#include <graphics.h>void main(){ int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); moveto(160,120); lineto(480,120); lineto(480,360); lineto(160,360); lineto(160,120); getch(); closegraph();}原创 2022-05-08 21:51:31 · 1436 阅读 · 0 评论 -
120.绘制直线
#include <graphics.h>void main(){ int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); line(160,120,480,120); line(480,120,480,360); line(480,360,160,360); line(160,360,160,120); getch(); closegraph();}.原创 2022-05-08 21:45:56 · 1401 阅读 · 0 评论 -
117.求定积分
#include "stdio.h"#include "math.h"double fsimpf(x) /*要进行计算的被积函数*/double x;{ double y; y=log(1.0+x)/(1.0+x*x); return(y);}double fsimp(a,b,eps) /*辛普森算法*/double a,b,eps; /*a为积分下限,b为积分上限,eps是希望达到的精度*/{ int n,k; double h,t1,t2,s1,.原创 2022-05-08 21:41:37 · 1356 阅读 · 0 评论 -
118.求满足特异条件的数列
#include<stdio.h>#define NUM 10 /*允许分解的最大元素数量*/int i[NUM]; /*记录分解出的数值的数组*/void main(){ int sum,n,total,k,flag,count=0; clrscr(); puts("*********************************************************"); puts("* This is a progr.原创 2022-05-08 21:44:05 · 1386 阅读 · 0 评论 -
116.复矩阵乘法
#include "stdio.h"#define MAX 255void CMatrixMul(ar,ai,br,bi,m,n,k,cr,ci) /*复矩阵相乘*/int m,n,k; /*m是矩阵A的行数,n是矩阵B的行数,k是矩阵B的列数*//*ar,br,cr分别是矩阵A,B,C的实部,ai,bi,ci分别是矩阵A,B, C的虚部*/double ar[],ai[],br[],bi[],cr[],ci[];{ int i,j,l,u,v,w; double p,q,s;.原创 2022-05-08 21:37:45 · 1433 阅读 · 0 评论 -
126.设置填充类型和填充颜色
/* set fill style */#include <graphics.h>void main(){ int i,c=4,x=5,y=6; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setcolor(c); for(i=c;i<c+8;i++) { setcolor(i); rectangle(x,y,x+140,y+104.原创 2022-05-04 20:15:35 · 1572 阅读 · 0 评论 -
125.设置线条类型
/* set line style */#include <graphics.h>void main(){ int i,j,c,x=50,y=50,k=1; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); setbkcolor(9); setcolor(4); for(j=1;j<=2;j++) { for(i=0;i<4;i++).原创 2022-05-04 20:14:43 · 1444 阅读 · 0 评论 -
124.设置背景色和前景色
/* set color */#include <graphics.h>void main(){ int cb,cf; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); for(cb=0;cb<=15;cb++) { setbkcolor(cb); for(cf=0;cf<=15;cf++) { setcolor(cf); .原创 2022-05-04 20:13:47 · 1502 阅读 · 0 评论 -
123.绘制椭圆/
#include <graphics.h>void main(){ int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc"); cleardevice(); moveto(160,120); linerel(320,0); linerel(0,240); linerel(-320,0); linerel(0,-240); getch(); closegraph();}原创 2022-05-04 20:12:53 · 1520 阅读 · 0 评论