Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
KN king Array ques
//Title of this code #include <stdio.h> #include<string.h> #include <stdlib.h> #include<time.h> int main(void) { int s; scanf("%d",&s); char a[s][s],flag[s][s]; int i,j,rn,p1,p2,n; for(i=0;i<s;i++) for(j=0;j<s;j++) a[i][j]='-'; for(i=0;i<s;i++) for(j=0;j<s;j++) flag[i][j]=0; srand( time(NULL)); i=rand() % s; j=rand() % s; a[i][j]='A'; n=0; p1=i;p2=j; while(n<25) { start: rn=(rand() % 500)%4; if(rn==0) { if(i-1>=0) { p1=i-1; p2=j; } else goto start; } else if(rn==1) { if(j+1<s) { p1=i; p2=j+1; } else goto start; } else if(rn==2) { if(i+1<s) { p1=i+1; p2=j; } else goto start; } else if(rn==3) { if(j-1>=0) { p1=i; p2=j-1; } else goto start; } if(flag[p1][p2]!=0) goto start; else flag[p1][p2]++; a[p1][p2]='B'+n; i=p1;j=p2; n++; } for(i=0;i<s;i++) { printf("\n"); { for(j=0;j<s;j++) printf("%c ",a[i][j]); } } return 0; }
run
|
edit
|
history
|
help
0
ternar
Lab 7 blackjack v1.0
Example array of struct print
String copy
tarea1
h
bitwise_operation__end-of-class
Project 3 part 2 Book v1
vetor mult
Bitwise Xor Swaping Two Variables