您的位置:

c语言spread,C语言sprintf函数

本文目录一览:

谁有c语言一些运行起来结果很好玩的程序的代码..

/*太大了估计你不想要,给你一个扫雷程序,turbo C下才能编译成功 空格:打标记 回车:扫雷 方向键:改变方向 */ #includestdio.h #includeconio.h #includetime.h void adjust(int*,int*); int a[23][23],c[22][22],mm,nn; int roundmine(int,int); void spread(); main() { int i,j,b[22][22],minenum,mine; int x,y,yy,s; char g,h,z; int*x1; int*y1; time_t t; again:srand((unsigned) time(t)); textcolor(LIGHTGREEN); for(i=2;i=21;i++) for(j=2;j=21;j++) { gotoxy(i,j); putch(219); b[i][j]=1; c[i][j]=1; } minenum=0; for(i=1;i=22;i++) for(j=1;j=22;j++) { a[i][j]=0; if(i1i22j1j22) {if((s=rand()%10)0) a[i][j]=0; else if(s==0) a[i][j]=1; } if(a[i][j]) minenum++; } gotoxy(50,2); puts("dirction"); gotoxy(50,3); puts("SPACE:mark"); gotoxy(50,4); puts("ENTER:dig"); gotoxy(50,8); printf("mine num:%4d",minenum); gotoxy(50,5); printf("ESC:exit"); gotoxy(30,15); puts(" "); gotoxy(30,20); puts(" "); mine=minenum; gotoxy(2,2); x=2;y=2; while(mine) { h=getch(); if(h=='H') gotoxy(x,--y); else if(h=='P') gotoxy(x,++y); else if(h=='K') gotoxy(--x,y); else if(h=='M') gotoxy(++x,y); x1=x;y1=y; adjust(x1,y1); if(h==' ') { if(c[wherex()][wherey()]) if(b[wherex()][wherey()]) { textcolor(LIGHTRED); putch(16); mine--; gotoxy(59,8); printf("%4d",mine); gotoxy(x,y); b[wherex()][wherey()]=0; } else { textcolor(LIGHTGREEN); putch(219); mine++; gotoxy(59,8); printf("%4d",mine); gotoxy(x,y); b[wherex()][wherey()]=1; } } if(h=='\015') { mm=wherex();nn=wherey(); c[wherex()][wherey()]=0; if(a[wherex()][wherey()]) { for(i=2;i=21;i++) for(j=2;j=21;j++) {gotoxy(i,j); if(a[i][j]) {textcolor(LIGHTRED); putch(017); } } break; } else {spread();gotoxy(mm,nn);} } if(h=='\033') exit(0); } yy=1; for(i=2;i=21;i++) for(j=2;j=21;j++) if (a[i][j]==1b[i][j]==1) {gotoxy(30,15); cprintf("You lose!!"); yy=0; } if(yy) {gotoxy(30,15); cprintf("You win!!"); } gotoxy(30,20); cprintf("Once again(y/n)?"); z=getch(); if(z=='y') goto again; } void adjust(int* x,int* y) { if(*x2) gotoxy(*x+=20,*y); else if(*x21) gotoxy(*x-=20,*y); else if(*y2) gotoxy(*x,*y+=20); else if(*y21) gotoxy(*x,*y-=20); } int roundmine(int x,int y) { int i,j,r=0; for(i=x-1;i=x+1;i++) for(j=y-1;j=y+1;j++) if(a[i][j]) r++; return r; } void spread() { int r,i,j,x,y; x=wherex(); y=wherey(); r=roundmine(x,y); if(r) {printf("%d",r);c[x][y]=0;} else if(r==0x1x22y1y22) { putchar(' ');c[x][y]=0; for(i=x-1;i=x+1;i++) for(j=y-1;j=y+1;j++) if(x1x22y1y22c[i][j]) {gotoxy(i,j); spread(); } } }

图 (c语言)

我来做,等等

/*编写无向图的邻接矩阵类AdjMWGraph,实现无向图的广度遍历和深度遍历。

其中,图中顶点数据类型为字符。Input第一行图中顶点的个数n(4=n=26)

第二行是图中边的条数m(3=m=351) 第三行是顶点信息(全为大写字母)

后面的输入数据是依附于一条边的两个顶点,有多少条边,就输入多少组信息。

注意:根结点都为A;并且所给字符连续,也就是说A B C D ……。

Output广度优先搜索序列。 深度优先搜索序列。

Sample Input

7

6

A B C D E F G

A B

A C

B D

B E

C F

C G

Sample Output

A B C D E F G

A B D E C F G

*/

#include stdio.h#include stdlib.h

unsigned char arrMap[26][26] = {0};

int nV = 0;

void deep_prior_scan(int j);

void spread_prior_scan(int j);

void GetResult()

{

int nL = 0;//存储边数

int i;

char arrV[26] = {0};

char temp, pairV[2];

//输入过程

printf("\n请输入顶点数:");

scanf("%d", nV);

printf("\n请输入边数:");

scanf("%d", nL);

printf("\n请依次输入顶点:\n");

for (i = 0, temp = 'A'; i nV; )

{

temp = getchar();

if (temp = 'A' temp = 'Z')

{

arrV[i++] = temp;

}

}

printf("\n请依次输入边:\n");

for (i = 0; i nL*2; )

{

temp = getchar();

if (temp = 'A' temp = 'Z')

{

pairV[i%2] = temp;

if (i%2 == 1)

{

arrMap[pairV[0] - 'A'][pairV[1] - 'A'] = 1;

}

++i;

}

}

//printf("\n广度优先遍历:\n");

//spread_prior_scan(0);

//printf("\n");

printf("\n深度优先遍历:\n");

deep_prior_scan(0);

printf("\n");

}

int main()

{

GetResult();

system("pause");

return 0;

}

void deep_prior_scan(int j)

{

int i;

printf("%c ", j + 'A');

for (i = 0; i nV; i++)

{

if (arrMap[j][i] != 0)

{

arrMap[j][i] = 0;

deep_prior_scan(i);

}

}

}

void spread_prior_scan(int j)

{

int i;

if (j == 0)

{

printf("\nA ");

}

if (j = 26)

{

printf("\nj=%d\n", j);

}

for (i = 0; i nV; i++)

{

if (arrMap[j][i] != 0)

{

printf("%c ", i + 'A');

}

}

for (i = 0; i nV; i++)

{

if (arrMap[j][i] != 0)

{

arrMap[j][i] = 0;

spread_prior_scan(i);

}

}

}

因为懒得复制数组,所以两种遍历方法要分开运行,你可以通过打开和关闭对相应函数的注释来得到两次的结果

c语言 求程序

具体什么公式不懂....

#include math.h

#include stdio.h

#include stdlib.h

#define KE 200

main()

{

float ex[KE],hy[KE],dx[KE],ix[KE];

float ga[KE],gb[KE];

float ex_low_m1=0, ex_low_m2=0, ex_high_m1=0, ex_high_m2=0;

int n,k,kc,ke,NSTEPS, kstart;

float ddx,dt,epsz,epsilon,sigma,eaf,freq_in,pi,arg;

float T,t0,spread,pulse;

FILE *fp;

// FILE *fopen(); 原程序有这个,错误,应删掉

/*printf("input freq(MHz):");

scanf("%f",freq);

freq=freq*1e6;*/

//初始化常量

ddx = 0.01;

dt = ddx/(2*3e8);

kc=KE/2;

pi=3.14159;

epsz=8.85419e-12;

/*initialze to free space*/

for(k=0;kKE;k++) //初始化所有输出空间

//提示输入非传导性

printf("dielectric starta at --");

scanf("%d",kstart);

//提示输入epsilon

printf("epsilon --");

scanf("%f",epsilon);

//提示输入传导性

printf("conductivity --");

scanf("%f",sigma);

printf("Kstart,epsilon,sigma:%d,%6.2f,%6.2f \n",kstart,epsilon,sigma);

/* eaf=dt*sigma/(2*epsz*epsilon);

printf("eaf:%6.4f \n",eaf); */

//根据公式填充ga,gb

for(k=kstart;k=KE;k++)

{

ga[k]=1./(1.+epsilon+sigma*dt/epsz);

gb[k]=sigma*dt/epsz;

}

//输出ga,gb

for(k=0;k=KE;k++)

//初始化所有空间为0

for(k=0;kKE;k++)

{

ex[k]=0; hy[k]=0;dx[k]=0;ix[k]=0;

}

/*these parametres specify the input pulse*/

//初始化参数

t0=50.0;

spread =20.0;

T=0;

NSTEPS=1;

//输入正数就一直计算,否则退出

while(NSTEPS0)

{

printf("NSTEPS---");

scanf("%d",NSTEPS);

printf("%d\n",NSTEPS);

//这里如果输入非正数仍会执行 如果需要退出,添加如下代码

// if (NSTEPS = 0) break;

// NSTEPS次循环

for(n=1;n=NSTEPS;n++)

{

T=T+1;

/*main fdtd loop*/

/*calculate the dx field*/

//根据公式填充dx

for(k=0;kKE;k++)

{

dx[k]=dx[k]+0.5*(hy[k-1]-hy[k]);

}

/* put gaussian pulse at the low end */

freq_in=3e8;

pulse=exp(-0.5*(pow( (t0-T)/spread,2.0)) );

/*pulse=sin(2*pi*freq*dt*T);*/

dx[kc]=dx[kc]+pulse;

//输出

printf("n=%d,T=%d,pulse=%6.2f\n",n,T,pulse);

printf("n=%d,dx[kc]=%6.2f\n",n,dx[kc]);

/*ex field*/

//根据公式填充ex, ix

for(k=1;kKE-1;k++)

{

ex[k]=ga[k]*(dx[k]-ix[k]);

ix[k]=ix[k]+gb[k]*ex[k];

}

/* absorbing boundary conditions*/

ex[0]= ex_low_m2;

ex_low_m2= ex_low_m1;

ex_low_m1=ex[1];

ex[KE-1]= ex_high_m2;

ex_high_m2= ex_high_m1;

ex_high_m1=ex[KE-2];

//根据公式填充hy

for(k=1;kKE-1;k++)

}

/* end of main fdtd loop*/

/*print the ex and hy fields*/

for(k=1;k=KE;k++)

printf("%3d %6.2f %6.2f\n",k,ex[k],hy[k]);

/*print the ex and hy fields to files*/

//输出ex到文件ex2.1

fp=fopen("ex2.1","w");

for(k=1;k=KE;k++)

fprintf(fp," %6.2f\n",ex[k]);

fclose(fp);

//输出hy到文件hy2.1

fp=fopen("hy2.1","w");

for(k=1;k=KE;k++)

fprintf(fp," %6.2f\n",hy[k]);

fclose(fp);

printf("T=%5.0f\n",T);

}

}