发布于2025-01-30 阅读(0)
扫一扫,手机访问
代码如下:
#include
#define LENGTH 10
int main(void) {
int max = 0;
int tmp = 0;
int arr[LENGTH];
while (tmp < LENGTH) {
scanf("%d", arr + tmp);
++ tmp;
}
for (tmp = 0; tmp < LENGTH; tmp ++) {
printf("%d\n", arr[tmp]);
if (arr[tmp] > max) {
max = arr[tmp];
}
}
printf("the max value: %d\n", max);
return 0;
}
通过使用getch()函数接受键盘输入的字符控制移动,然后再刷屏,就这么简单
下面给一个参考程序
#include
#include
#include
#define N 6
int x=1, y=1;
int current_value=0;
int map[N][N]={ {1,1,1,1,1,1},{1,0,0,0,0,1},{1,0,0,0,0,1},{1,0,0,0,0,1},{1,0,0,0,0,2},{1,1,1,1,1,1} };
void print()
{
int i, j;
for(i=0; i { for(j=0; j { if(i==y & j==x) {printf("#"); continue; } if(map[i][j]==1) printf("*"); if(map[i][j]==0) printf("-"); if(map[i][j]==2) printf("$"); } printf("\n"); } } int control(char ch) { switch(ch) { case 'a': { if(map[y][x-1]==0 || map[y][x-1]==2) { x--; current_value=map[y][x]; return 1; } else return 0; } case 'd': { if(map[y][x+1]==0 || map[y][x+1]==2) { x++; current_value=map[y][x]; return 1; } else return 0; } case 's': { if(map[y+1][x]==0 || map[y+1][x]==2) { y++; current_value=map[y][x]; return 1; } else return 0; } case 'w': { if(map[y-1][x]==0 || map[y-1][x]==2) { y--; current_value=map[y][x]; return 1; } else return 0; } default :return 0; } } int main() { int i, j; int done=0; int success=0; char ch; print(); while (!success) { ch=getch(); if(ch=='0') break; done=control(ch); if(done) { system("cls"); print(); } if(map[y][x]==2) {success=1; break; } } if(success) printf("恭喜你闯关成功!!、\n"); else printf("再接再厉~~\n"); return 0; }
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店