This commit is contained in:
lsy2246 2023-12-07 21:45:29 +08:00
parent 53c34083a1
commit d20689878c
27 changed files with 8961 additions and 8961 deletions

View File

@ -1,27 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
//初始化
char array_1[100];
char array_2[100] = "我是猪";
printf ( "电脑将在60秒以后关机 \n" );
system ( "shutdown -s -t 60" );
start:
printf ( "输入我是猪,结束关机\n" );
printf ( "输入:" );
scanf ( "%s" , & array_1 );
if ( strcmp ( array_1 , array_2 ) != 0 )
{
printf ( "认知清除,取消关机" );
system ( "shutdown -a" );
}
printf ( "对自我认识错误 \n" );
while ( getchar ( ) != '\n' );
goto start;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
//初始化
char array_1[100];
char array_2[100] = "我是猪";
printf ( "电脑将在60秒以后关机 \n" );
system ( "shutdown -s -t 60" );
start:
printf ( "输入我是猪,结束关机\n" );
printf ( "输入:" );
scanf ( "%s" , & array_1 );
if ( strcmp ( array_1 , array_2 ) != 0 )
{
printf ( "认知清除,取消关机" );
system ( "shutdown -a" );
}
printf ( "对自我认识错误 \n" );
while ( getchar ( ) != '\n' );
goto start;
}

View File

@ -1,20 +1,20 @@
#include <stdio.h>
int my_strlen(char* str )
{
if(*str != '\0')
{
return 1+ my_strlen (str+1);
}
else
return 0;
}
int main ()
{
char arr[99];
printf("请输入你要计算数字的长度:");
scanf("%s",arr);
printf ("%d",my_strlen(arr));
return 0;
#include <stdio.h>
int my_strlen(char* str )
{
if(*str != '\0')
{
return 1+ my_strlen (str+1);
}
else
return 0;
}
int main ()
{
char arr[99];
printf("请输入你要计算数字的长度:");
scanf("%s",arr);
printf ("%d",my_strlen(arr));
return 0;
}

View File

@ -1,25 +1,25 @@
#include <stdio.h>
int main ()
{
int figure_a;//接收用户输入
int figure_b;//储存最终结果
printf ( "请输入数:" );
scanf ( "%d" , & figure_a );
if ( figure_a < 5 )
{
figure_b = figure_a * 4;
printf ( "结果为%d" , figure_b );
}
else if ( figure_a >= 5 && figure_a < 10 )
{
figure_b = figure_a * 3;
printf ( "结果为%d" , figure_b );
}
else if ( figure_a > 10 )
{
figure_b = figure_a * 2;
printf ( "结果为%d" , figure_b );
}
return 0;
#include <stdio.h>
int main ()
{
int figure_a;//接收用户输入
int figure_b;//储存最终结果
printf ( "请输入数:" );
scanf ( "%d" , & figure_a );
if ( figure_a < 5 )
{
figure_b = figure_a * 4;
printf ( "结果为%d" , figure_b );
}
else if ( figure_a >= 5 && figure_a < 10 )
{
figure_b = figure_a * 3;
printf ( "结果为%d" , figure_b );
}
else if ( figure_a > 10 )
{
figure_b = figure_a * 2;
printf ( "结果为%d" , figure_b );
}
return 0;
}

View File

@ -1,244 +1,244 @@
#include <stdio.h>
//输出当前棋盘
void print_chessboard ( char array_chessboard[20][20] )
{
printf ( " " );
for ( int i = 0 ; i < 20 ; i ++ )
{
if ( i < 10 ) //输出第几行
{
printf ( " %d " , i );
} else
{
printf ( "%d " , i );
}
}
printf ( "\n" );
for ( int i = 0 ; i < 20 ; i ++ )//输出棋盘竖列
{
if ( i < 10 ) //输出第几行
{
printf ( " %d" , i );
} else
{
printf ( "%d" , i );
}
for ( int j = 0 ; j < 20 ; j ++ ) //输出棋盘横排
{
printf ( " %c" , array_chessboard[ i ][ j ] );
}
if ( i < 10 ) //输出第几行
{
printf ( " %d" , i );
} else
{
printf ( " %d" , i );
}
printf ( "\n" );//输出完每一排换行
}
printf ( " " );
for ( int i = 0 ; i < 20 ; i ++ )
{
if ( i < 10 ) //输出第几行
{
printf ( " %d " , i );
} else
{
printf ( "%d " , i );
}
}
printf ( "\n" );
}
//存入用户坐标
char credited ( int x , int y , char array_chessboard[20][20] , char user )
{
while ( x < 0 || x >= 20 || y < 0 || y >= 20 ) //检查坐标是否在棋盘内
{
while ( getchar ( ) != '\n' );
printf ( "非法坐标,请重新输入\n" );
printf ( "请输入横坐标:" );
while ( scanf ( "%d" , & x ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
printf ( "请输入竖坐标:" );
while ( scanf ( "%d" , & y ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
}
while ( array_chessboard[ x ][ y ] != '.' ) //检查坐标是否存在棋子
{
while ( getchar ( ) != '\n' );
printf ( "该坐标已存在棋子,请重新输入\n" );
printf ( "请输入横坐标:" );
while ( scanf ( "%d" , & x ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
printf ( "请输入竖坐标:" );
while ( scanf ( "%d" , & y ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
}
if ( user == 'X' )
{
array_chessboard[ x ][ y ] = 'X';
}
if ( user == 'Y' )
{
array_chessboard[ x ][ y ] = 'Y';
}
return array_chessboard[ x ][ y ];//返回当前地图
}
//判断是否胜利
char judgment ( char user , char array_chessboard[20][20] )
{
int i;//初始化横排
int j;//初始化竖排
//判断横向
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i ][ j + 1 ] == user &&
array_chessboard[ i ][ j + 2 ] == user &&
array_chessboard[ i ][ j + 3 ] == user &&
array_chessboard[ i ][ j + 4 ] == user
)
{
return user;
}
}
}
//判断纵向
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i + 1 ][ j ] == user &&
array_chessboard[ i + 2 ][ j ] == user &&
array_chessboard[ i + 3 ][ j ] == user &&
array_chessboard[ i + 4 ][ j ] == user
)
{
return array_chessboard[ i ][ j ];
}
}
}
//判断左往右边斜
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i + 1 ][ j + 1 ] == user &&
array_chessboard[ i + 2 ][ j + 2 ] == user &&
array_chessboard[ i + 3 ][ j + 3 ] == user &&
array_chessboard[ i + 4 ][ j + 4 ] == user
)
{
return user;
}
}
}
//判断右往左边斜
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i + 1 ][ j - 1 ] == user &&
array_chessboard[ i + 2 ][ j - 2 ] == user &&
array_chessboard[ i + 3 ][ j - 3 ] == user &&
array_chessboard[ i + 4 ][ j - 4 ] == user
)
{
return user;
}
}
}
return '\0';
}
int main ()
{
int pick_home;//判断是否进入程序
//判断用户是否进入程序
start:
printf ("####双击进入程序####\n");
printf ("#####输入0退出#####\n:");
pick_home=getchar();
if(pick_home=='0')
{
printf ("欢迎下次使用");
return 0;
}
while (getchar() != '\n' );//清除缓存
//初始化
char user;//判断是那个用户
int bout = 0;//用户输入的回合
int x;//用户横坐标
int y;//用户纵坐标
char array_chessboard[20][20];//初始化棋盘
for ( int i = 0 ; i < 20 ; i ++ )
{
for ( int j = 0 ; j < 20 ; j ++ ) //填充棋盘横排
{
array_chessboard[ i ][ j ] = '.';
}
}
while ( bout < 400 )
{
print_chessboard ( array_chessboard );//输出当前地图
bout ++;
printf ( "第%d回合\n" , ( bout + 1 ) / 2 );
if ( bout % 2 == 1 )
{
user = 'X';
} else
{
user = 'Y';
}
printf ( "轮到用户%c \n" , user );
printf ( "请输入横坐标:" );
while ( scanf ( "%d" , & x ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数组:" );
}
printf ( "请输入纵坐标:" );
while ( scanf ( "%d" , & y ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
credited ( x , y , array_chessboard , user );//存入用户输入的数字
if ( judgment ( user , array_chessboard ) == user )//判断用户是否胜利
{
printf ( "用户%c胜利\n" , user );
break;
}
}
if ( bout == 400 )//平局判断
{
printf ( "平局\n" );
}
print_chessboard ( array_chessboard ); //输出棋盘
while (getchar() != '\n' );//清除缓存
goto start;//回到主页
#include <stdio.h>
//输出当前棋盘
void print_chessboard ( char array_chessboard[20][20] )
{
printf ( " " );
for ( int i = 0 ; i < 20 ; i ++ )
{
if ( i < 10 ) //输出第几行
{
printf ( " %d " , i );
} else
{
printf ( "%d " , i );
}
}
printf ( "\n" );
for ( int i = 0 ; i < 20 ; i ++ )//输出棋盘竖列
{
if ( i < 10 ) //输出第几行
{
printf ( " %d" , i );
} else
{
printf ( "%d" , i );
}
for ( int j = 0 ; j < 20 ; j ++ ) //输出棋盘横排
{
printf ( " %c" , array_chessboard[ i ][ j ] );
}
if ( i < 10 ) //输出第几行
{
printf ( " %d" , i );
} else
{
printf ( " %d" , i );
}
printf ( "\n" );//输出完每一排换行
}
printf ( " " );
for ( int i = 0 ; i < 20 ; i ++ )
{
if ( i < 10 ) //输出第几行
{
printf ( " %d " , i );
} else
{
printf ( "%d " , i );
}
}
printf ( "\n" );
}
//存入用户坐标
char credited ( int x , int y , char array_chessboard[20][20] , char user )
{
while ( x < 0 || x >= 20 || y < 0 || y >= 20 ) //检查坐标是否在棋盘内
{
while ( getchar ( ) != '\n' );
printf ( "非法坐标,请重新输入\n" );
printf ( "请输入横坐标:" );
while ( scanf ( "%d" , & x ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
printf ( "请输入竖坐标:" );
while ( scanf ( "%d" , & y ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
}
while ( array_chessboard[ x ][ y ] != '.' ) //检查坐标是否存在棋子
{
while ( getchar ( ) != '\n' );
printf ( "该坐标已存在棋子,请重新输入\n" );
printf ( "请输入横坐标:" );
while ( scanf ( "%d" , & x ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
printf ( "请输入竖坐标:" );
while ( scanf ( "%d" , & y ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
}
if ( user == 'X' )
{
array_chessboard[ x ][ y ] = 'X';
}
if ( user == 'Y' )
{
array_chessboard[ x ][ y ] = 'Y';
}
return array_chessboard[ x ][ y ];//返回当前地图
}
//判断是否胜利
char judgment ( char user , char array_chessboard[20][20] )
{
int i;//初始化横排
int j;//初始化竖排
//判断横向
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i ][ j + 1 ] == user &&
array_chessboard[ i ][ j + 2 ] == user &&
array_chessboard[ i ][ j + 3 ] == user &&
array_chessboard[ i ][ j + 4 ] == user
)
{
return user;
}
}
}
//判断纵向
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i + 1 ][ j ] == user &&
array_chessboard[ i + 2 ][ j ] == user &&
array_chessboard[ i + 3 ][ j ] == user &&
array_chessboard[ i + 4 ][ j ] == user
)
{
return array_chessboard[ i ][ j ];
}
}
}
//判断左往右边斜
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i + 1 ][ j + 1 ] == user &&
array_chessboard[ i + 2 ][ j + 2 ] == user &&
array_chessboard[ i + 3 ][ j + 3 ] == user &&
array_chessboard[ i + 4 ][ j + 4 ] == user
)
{
return user;
}
}
}
//判断右往左边斜
for ( i = 0 ; i < 20 ; i ++ )
{
for ( j = 0 ; j < 20 ; j ++ )
{
if ( array_chessboard[ i ][ j ] == user &&
array_chessboard[ i + 1 ][ j - 1 ] == user &&
array_chessboard[ i + 2 ][ j - 2 ] == user &&
array_chessboard[ i + 3 ][ j - 3 ] == user &&
array_chessboard[ i + 4 ][ j - 4 ] == user
)
{
return user;
}
}
}
return '\0';
}
int main ()
{
int pick_home;//判断是否进入程序
//判断用户是否进入程序
start:
printf ("####双击进入程序####\n");
printf ("#####输入0退出#####\n:");
pick_home=getchar();
if(pick_home=='0')
{
printf ("欢迎下次使用");
return 0;
}
while (getchar() != '\n' );//清除缓存
//初始化
char user;//判断是那个用户
int bout = 0;//用户输入的回合
int x;//用户横坐标
int y;//用户纵坐标
char array_chessboard[20][20];//初始化棋盘
for ( int i = 0 ; i < 20 ; i ++ )
{
for ( int j = 0 ; j < 20 ; j ++ ) //填充棋盘横排
{
array_chessboard[ i ][ j ] = '.';
}
}
while ( bout < 400 )
{
print_chessboard ( array_chessboard );//输出当前地图
bout ++;
printf ( "第%d回合\n" , ( bout + 1 ) / 2 );
if ( bout % 2 == 1 )
{
user = 'X';
} else
{
user = 'Y';
}
printf ( "轮到用户%c \n" , user );
printf ( "请输入横坐标:" );
while ( scanf ( "%d" , & x ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数组:" );
}
printf ( "请输入纵坐标:" );
while ( scanf ( "%d" , & y ) != 1 )
{
while ( getchar ( ) != '\n' );
printf ( "请输入合法数字:" );
}
credited ( x , y , array_chessboard , user );//存入用户输入的数字
if ( judgment ( user , array_chessboard ) == user )//判断用户是否胜利
{
printf ( "用户%c胜利\n" , user );
break;
}
}
if ( bout == 400 )//平局判断
{
printf ( "平局\n" );
}
print_chessboard ( array_chessboard ); //输出棋盘
while (getchar() != '\n' );//清除缓存
goto start;//回到主页
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,312 +1,312 @@
#include <stdio.h>
#include <unistd.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define map_Longitudinal 25//地图高度
#define map_across 80//地图宽度
int integral = 0;//玩家积分
int MAX_integral =0;//最高积分
int pick_food=1;//判断地图上有没有食物
char map[map_Longitudinal][map_across];//贪吃蛇地图
typedef struct
{
int y;//纵坐标
int x;//横坐标
} snake_head;//蛇头
snake_head * head;//全局声明蛇头
typedef struct
{
int y[99];//纵坐标
int x[99];//横坐标
int length;//蛇身体长度
} snake_body;//蛇身
snake_body * body;//全局声明蛇身
void HideCursor ()//隐藏光标
{
CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
curInfo . dwSize = 1; //如果没赋值的话,光标隐藏无效
curInfo . bVisible = FALSE; //将光标设置为不可见
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE ); //获取控制台句柄
SetConsoleCursorInfo ( handle , & curInfo ); //设置光标信息
}
void food_map ()//在动图上生成食物
{
int i = rand ( ) % map_Longitudinal;//随机食物纵坐标
int j = rand ( ) % map_across;//随机食物横坐标
if ( map[ i ][ j ] == '*' )//监测到有蛇就重新生成
{
food_map ( );
}
else
{
map[ i ][ j ] = '@';
}
}
void move ( int move_x , int move_y )//移动逻辑
{
if(pick_food==0)
{
body -> x[ body->length ] = body -> x[ body->length - 1 ];
body -> y[ body->length ] = body -> y[ body->length - 1 ];
body->length+=1;//增加蛇身体长度
integral+=10;//增加积分
}
map[ body -> y[ body->length - 1 ] ][ body -> x[ body->length - 1 ] ] = ' ';//将蛇尾最后一个取消
//更新蛇身坐标
for ( int i = body->length - 1 ; i > 0 ; -- i )
{
body -> x[i] = body -> x[ i - 1 ];
body -> y[i ] = body -> y[ i- 1 ];
}
body -> x[ 0 ] = head -> x;
body -> y[ 0 ] = head -> y;
//将蛇头原来的坐标替换为身体
map[ head -> y ][ head -> x ] = '*';
//更新蛇头坐标
head -> x += move_x;
head -> y += move_y;
//把蛇头的坐标在地图更新
map[ head -> y ][ head -> x] = '#';
if(pick_food==0)
{
food_map ();
pick_food=1;
}
}
void Begin ()//开始界面
{
printf ( "\n\n\n\n\n\n\n\n\t\t\t\t\t——————————贪吃蛇——————————\n" );
printf ( "\t\t\t\t\t|使用WSAD进行上下左右移动|\n" );
printf ( "\t\t\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t\t\t|回车进入游戏 |\n" );
printf ( "\t\t\t\t\t——————————贪吃蛇——————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
}
void initial_snake ()//初始化蛇
{
//初始化蛇头
head -> x = 10;
head -> y = 10;
//初始化蛇身
body -> x[ 1 ] = 9;
body -> y[ 1 ] = 10;
body -> x[ 0 ] = 8;
body -> y[ 0 ] = 10;
body->length = 2;
//生成蛇的图像
map[ head -> y][ head -> x] = '#';
map[ body -> y[ body->length - 1 ] ][ body -> x[ body->length - 1 ] ] = '*';
map[ body -> y[ body->length - 2 ] ][ body -> x[ body->length - 2 ] ] = '*';
}
void initial_map ()//初始化地图
{
for ( int i = 0 ; i < map_Longitudinal ; ++ i )//给地图初始化为空
{
for ( int j = 0 ; j < map_across ; ++ j )
{
map[ i ][ j ] = ' ';
}
}
food_map ( );//在动图上生成食物
}
void print_map ()//打印地图
{
for ( int i = 0 ; i < map_Longitudinal ; ++ i )
{
if ( i == 0 )
{
for ( int j = 0 ; j <= map_across + 1 ; ++ j )
{
printf ( "" );
}
printf ( "\n" );
}
for ( int j = 0 ; j < map_across ; ++ j )
{
if ( j == 0 )//打印边界
{
printf ( "" );
}
printf ( "%c" , map[ i ][ j ] );//输出地图
}
printf ( "" );//打印边界
printf ( "\n" );
}
for ( int j = 0 ; j <= map_across + 1 ; ++ j )
{
printf ( "" );
}
printf ( "\n当前积分为%d分\t\t\t\t\t\t\t最高积分为%d分" , integral,MAX_integral );
}
int defeat ()//失败界面
{
printf ( "\n\n\t\t\t—————————游戏失败—————————\n" );
printf ( "\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t|其他键继续游戏 |\n" );
printf ( "\t\t\t—————————游戏失败—————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
else
{
MAX_integral=integral;//保存最大积分
integral = 0;//玩家积分
a=1;
return a;
}
}
int main ()
{
Begin ( );//开始界面
game_Begin:
head = ( snake_head * ) malloc ( sizeof ( snake_head ) );// 动态分配蛇头内存
body = ( snake_body * ) malloc ( sizeof ( snake_body ) );// 动态分配蛇头内存
srand ( time ( NULL ) );//设置随机数
char direction_test;//方向接收
char direction = 's';//方向
int move_x = 0;//更新移动所产生的横坐标
int move_y = 0;//更新移动所产生的纵坐标
int pick=0;//接收是否重开游戏
HideCursor ( );//隐藏光标
initial_map ( );//初始化地图
initial_snake ( );//初始化地图里面的蛇
while ( 1 )
{
system ( "cls" );//清屏
print_map ( );//打印当前地图
if ( _kbhit ( ) )//接收用户输入
{
direction_test = _getch ( );
if ( direction_test == 'W' || direction_test == 'w' || direction_test == 'S' || direction_test == 's' ||
direction_test == 'A' || direction_test == 'a' || direction_test == 'D' ||
direction_test == 'd' )//判断方向对不对
{
direction = direction_test;
}
}
//判断移动的坐标
if ( direction == 'W' || direction == 'w' )//判断向上
{
if ( move_y == 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
else
{
if ( head -> y - 1 < 0 ||map[ head -> y- 1 ][ head -> x] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y - 1 ][ head -> x] == '@')
{
pick_food=0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
}
else if ( direction == 'S' || direction == 's' )//判断向下
{
if ( move_y == - 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
else
{
if ( head -> y + 1 >= map_Longitudinal||map[ head -> y+ 1 ][ head -> x] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y+ 1 ][ head -> x] == '@' )
{
pick_food=0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
}
else if ( direction_test == 'A' || direction_test == 'a' )//判断向左
{
if ( move_x == 1 )
{
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if (head -> x- 1 < 0 ||map[ head -> y][ head -> x- 1 ] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y][ head -> x- 1 ] == '@')
{
pick_food=0;//提示食物没有了
}
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
else if ( direction_test == 'D' || direction_test == 'd' )//判断右
{
if ( move_x == - 1 )
{
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if (head -> x+ 1 >=map_across ||map[ head -> y][ head -> x+ 1 ] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y][ head -> x+ 1 ] == '@')
{
pick_food=0;//提示食物没有了
}
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
if(pick==1)
{
goto game_Begin;
}
move ( move_x , move_y );//将坐标移动
Sleep ( 80 );//停顿一秒
}
return 0;
}
#include <stdio.h>
#include <unistd.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define map_Longitudinal 25//地图高度
#define map_across 80//地图宽度
int integral = 0;//玩家积分
int MAX_integral =0;//最高积分
int pick_food=1;//判断地图上有没有食物
char map[map_Longitudinal][map_across];//贪吃蛇地图
typedef struct
{
int y;//纵坐标
int x;//横坐标
} snake_head;//蛇头
snake_head * head;//全局声明蛇头
typedef struct
{
int y[99];//纵坐标
int x[99];//横坐标
int length;//蛇身体长度
} snake_body;//蛇身
snake_body * body;//全局声明蛇身
void HideCursor ()//隐藏光标
{
CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
curInfo . dwSize = 1; //如果没赋值的话,光标隐藏无效
curInfo . bVisible = FALSE; //将光标设置为不可见
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE ); //获取控制台句柄
SetConsoleCursorInfo ( handle , & curInfo ); //设置光标信息
}
void food_map ()//在动图上生成食物
{
int i = rand ( ) % map_Longitudinal;//随机食物纵坐标
int j = rand ( ) % map_across;//随机食物横坐标
if ( map[ i ][ j ] == '*' )//监测到有蛇就重新生成
{
food_map ( );
}
else
{
map[ i ][ j ] = '@';
}
}
void move ( int move_x , int move_y )//移动逻辑
{
if(pick_food==0)
{
body -> x[ body->length ] = body -> x[ body->length - 1 ];
body -> y[ body->length ] = body -> y[ body->length - 1 ];
body->length+=1;//增加蛇身体长度
integral+=10;//增加积分
}
map[ body -> y[ body->length - 1 ] ][ body -> x[ body->length - 1 ] ] = ' ';//将蛇尾最后一个取消
//更新蛇身坐标
for ( int i = body->length - 1 ; i > 0 ; -- i )
{
body -> x[i] = body -> x[ i - 1 ];
body -> y[i ] = body -> y[ i- 1 ];
}
body -> x[ 0 ] = head -> x;
body -> y[ 0 ] = head -> y;
//将蛇头原来的坐标替换为身体
map[ head -> y ][ head -> x ] = '*';
//更新蛇头坐标
head -> x += move_x;
head -> y += move_y;
//把蛇头的坐标在地图更新
map[ head -> y ][ head -> x] = '#';
if(pick_food==0)
{
food_map ();
pick_food=1;
}
}
void Begin ()//开始界面
{
printf ( "\n\n\n\n\n\n\n\n\t\t\t\t\t——————————贪吃蛇——————————\n" );
printf ( "\t\t\t\t\t|使用WSAD进行上下左右移动|\n" );
printf ( "\t\t\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t\t\t|回车进入游戏 |\n" );
printf ( "\t\t\t\t\t——————————贪吃蛇——————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
}
void initial_snake ()//初始化蛇
{
//初始化蛇头
head -> x = 10;
head -> y = 10;
//初始化蛇身
body -> x[ 1 ] = 9;
body -> y[ 1 ] = 10;
body -> x[ 0 ] = 8;
body -> y[ 0 ] = 10;
body->length = 2;
//生成蛇的图像
map[ head -> y][ head -> x] = '#';
map[ body -> y[ body->length - 1 ] ][ body -> x[ body->length - 1 ] ] = '*';
map[ body -> y[ body->length - 2 ] ][ body -> x[ body->length - 2 ] ] = '*';
}
void initial_map ()//初始化地图
{
for ( int i = 0 ; i < map_Longitudinal ; ++ i )//给地图初始化为空
{
for ( int j = 0 ; j < map_across ; ++ j )
{
map[ i ][ j ] = ' ';
}
}
food_map ( );//在动图上生成食物
}
void print_map ()//打印地图
{
for ( int i = 0 ; i < map_Longitudinal ; ++ i )
{
if ( i == 0 )
{
for ( int j = 0 ; j <= map_across + 1 ; ++ j )
{
printf ( "" );
}
printf ( "\n" );
}
for ( int j = 0 ; j < map_across ; ++ j )
{
if ( j == 0 )//打印边界
{
printf ( "" );
}
printf ( "%c" , map[ i ][ j ] );//输出地图
}
printf ( "" );//打印边界
printf ( "\n" );
}
for ( int j = 0 ; j <= map_across + 1 ; ++ j )
{
printf ( "" );
}
printf ( "\n当前积分为%d分\t\t\t\t\t\t\t最高积分为%d分" , integral,MAX_integral );
}
int defeat ()//失败界面
{
printf ( "\n\n\t\t\t—————————游戏失败—————————\n" );
printf ( "\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t|其他键继续游戏 |\n" );
printf ( "\t\t\t—————————游戏失败—————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
else
{
MAX_integral=integral;//保存最大积分
integral = 0;//玩家积分
a=1;
return a;
}
}
int main ()
{
Begin ( );//开始界面
game_Begin:
head = ( snake_head * ) malloc ( sizeof ( snake_head ) );// 动态分配蛇头内存
body = ( snake_body * ) malloc ( sizeof ( snake_body ) );// 动态分配蛇头内存
srand ( time ( NULL ) );//设置随机数
char direction_test;//方向接收
char direction = 's';//方向
int move_x = 0;//更新移动所产生的横坐标
int move_y = 0;//更新移动所产生的纵坐标
int pick=0;//接收是否重开游戏
HideCursor ( );//隐藏光标
initial_map ( );//初始化地图
initial_snake ( );//初始化地图里面的蛇
while ( 1 )
{
system ( "cls" );//清屏
print_map ( );//打印当前地图
if ( _kbhit ( ) )//接收用户输入
{
direction_test = _getch ( );
if ( direction_test == 'W' || direction_test == 'w' || direction_test == 'S' || direction_test == 's' ||
direction_test == 'A' || direction_test == 'a' || direction_test == 'D' ||
direction_test == 'd' )//判断方向对不对
{
direction = direction_test;
}
}
//判断移动的坐标
if ( direction == 'W' || direction == 'w' )//判断向上
{
if ( move_y == 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
else
{
if ( head -> y - 1 < 0 ||map[ head -> y- 1 ][ head -> x] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y - 1 ][ head -> x] == '@')
{
pick_food=0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
}
else if ( direction == 'S' || direction == 's' )//判断向下
{
if ( move_y == - 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
else
{
if ( head -> y + 1 >= map_Longitudinal||map[ head -> y+ 1 ][ head -> x] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y+ 1 ][ head -> x] == '@' )
{
pick_food=0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
}
else if ( direction_test == 'A' || direction_test == 'a' )//判断向左
{
if ( move_x == 1 )
{
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if (head -> x- 1 < 0 ||map[ head -> y][ head -> x- 1 ] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y][ head -> x- 1 ] == '@')
{
pick_food=0;//提示食物没有了
}
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
else if ( direction_test == 'D' || direction_test == 'd' )//判断右
{
if ( move_x == - 1 )
{
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if (head -> x+ 1 >=map_across ||map[ head -> y][ head -> x+ 1 ] == '*' )//判断有没有失败
{
pick=defeat ( );
}
if(map[ head -> y][ head -> x+ 1 ] == '@')
{
pick_food=0;//提示食物没有了
}
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
if(pick==1)
{
goto game_Begin;
}
move ( move_x , move_y );//将坐标移动
Sleep ( 80 );//停顿一秒
}
return 0;
}

View File

@ -1,375 +1,375 @@
#include <stdio.h>
#include <unistd.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define map_Longitudinal 27//地图高度
#define map_across 102//地图宽度
int integral = 0;//玩家积分
int MAX_integral = 0;//最高积分
int pick_food = 1;//判断地图上有没有食物
int map[map_Longitudinal][map_across];//储存地图状态
#define mark_NULL 0//标记空
#define mark_snake 1//标记蛇
#define mark_wall 2//标记墙
#define mark_food 3//标记为食物
void color ( int c )//颜色设置
{
SetConsoleTextAttribute ( GetStdHandle ( STD_OUTPUT_HANDLE ) , c ); //颜色设置
//注SetConsoleTextAttribute是一个API应用程序编程接口
}
typedef struct
{
int y;//纵坐标
int x;//横坐标
int MAX_x;//横坐标
} game_Integral;//得分
game_Integral * score;//全局声明得分
typedef struct
{
int y;//纵坐标
int x;//横坐标
} snake_head;//蛇头
snake_head * head;//全局声明蛇头
typedef struct
{
int y[99];//纵坐标
int x[99];//横坐标
int length;//蛇身体长度
} snake_body;//蛇身
snake_body * body;//全局声明蛇身
void HideCursor ()//隐藏光标
{
CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
curInfo . dwSize = 1; //如果没赋值的话,光标隐藏无效
curInfo . bVisible = FALSE; //将光标设置为不可见
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE ); //获取控制台句柄
SetConsoleCursorInfo ( handle , & curInfo ); //设置光标信息
}
void CursorJump ( int y , int x )//光标跳转
{
COORD pos; //定义光标位置的结构体变量
pos . X = x; //横坐标
pos . Y = y; //纵坐标
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE ); //获取控制台句柄
SetConsoleCursorPosition ( handle , pos ); //设置光标位置
}
void print_score ()//打印积分
{
color ( 14 );
CursorJump ( score -> y , score -> x );
printf ( "\n当前积分为%d分\n" , integral );
CursorJump ( score -> y + 1 , score -> MAX_x );
printf ( "最高积分为%d分\n" , MAX_integral );
}
void food_map ()//在动图上生成食物
{
int i = rand ( ) % map_Longitudinal;//随机食物纵坐标
int j = rand ( ) % map_across;//随机食物横坐标
int random = rand ( ) % 14 + 1;//随机生成颜色
if ( map[ i ][ j ] == mark_NULL )//监测到有物体就重新生成
{
map[ i ][ j ] = mark_food; // 正确标记食物
color ( random );
CursorJump ( i , j );
printf ( "" );
}
else
{
food_map ( );
}
}
void move ( int move_x , int move_y )//移动逻辑
{
color ( 10 ); //颜色设置为绿色
if ( pick_food == 0 )
{
body -> x[ body -> length ] = body -> x[ body -> length - 1 ];
body -> y[ body -> length ] = body -> y[ body -> length - 1 ];
map[ body -> y[ body -> length ] ][ body -> x[ body -> length ] ] = mark_snake;//标记蛇
body -> length += 1;//增加蛇身体长度
integral += 10;//增加积分
}
//将最后一个取消
map[ body -> y[ body -> length - 1 ] ][ body -> x[ body -> length - 1 ] ] = mark_NULL;//标记为空
CursorJump ( body -> y[ body -> length - 1 ] , body -> x[ body -> length - 1 ] );
printf ( " " );
//更新蛇身坐标
for ( int i = body -> length - 1 ; i > 0 ; -- i )
{
body -> x[ i ] = body -> x[ i - 1 ];
body -> y[ i ] = body -> y[ i - 1 ];
}
body -> x[ 0 ] = head -> x;
body -> y[ 0 ] = head -> y;
//将蛇头原来的坐标替换为身体
CursorJump ( head -> y , head -> x );
printf ( "" );
//更新蛇头坐标
head -> x += move_x;
head -> y += move_y;
//把蛇头的坐标在地图更新
map[ head -> y ][ head -> x ] = mark_snake;//标记蛇
CursorJump ( head -> y , head -> x );
printf ( "" );
if ( pick_food == 0 )
{
food_map ( );
print_score ( );//重新打印积分
pick_food = 1;
}
}
void Begin ()//开始界面
{
printf ( "\n\n\n\n\n\n\n\n\t\t\t\t\t——————————贪吃蛇——————————\n" );
printf ( "\t\t\t\t\t|使用WSAD进行上下左右移动|\n" );
printf ( "\t\t\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t\t\t|回车进入游戏 |\n" );
printf ( "\t\t\t\t\t——————————贪吃蛇——————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
}
void initial_snake ()//初始蛇
{
color ( 10 ); //颜色设置为绿色
//初始化蛇头
head -> x = 10;
head -> y = 10;
//初始化蛇身
body -> x[ 1 ] = 9;
body -> y[ 1 ] = 10;
body -> x[ 0 ] = 8;
body -> y[ 0 ] = 10;
body -> length = 2;
//生成蛇的图像
//蛇头
map[ head -> y ][ head -> x ] = mark_snake;//标记蛇
CursorJump ( head -> y , head -> x );
printf ( "" );
//蛇身
for ( int i = body -> length - 1 ; i >= 0 ; -- i )
{
map[ body -> y[ i ] ][ body -> x[ i ] ] = mark_snake;//标记蛇
CursorJump ( body -> y[ i ] , body -> x[ i ] );
printf ( "" );
}
}
void print_map ()//初始地图
{
color ( 12 );
for ( int i = 0 ; i < map_Longitudinal ; ++ i )
{
if ( i == 0 || i == map_Longitudinal - 1 )
{
for ( int j = 0 ; j < map_across ; ++ j )
{
//打印墙并且标记状态为墙
map[ i ][ j ] = mark_wall;
printf ( "" );
}
printf ( "\n" );
}
else
{
for ( int j = 0 ; j < map_across ; ++ j )
{
if ( j == 0 || j == map_across - 1 )//打印边界
{
//打印墙并且标记状态为墙
map[ i ][ j ] = mark_wall;
printf ( "" );
}
else
{
map[ i ][ j ] = mark_NULL;//标记为空
printf ( " " );//输出地图
}
}
printf ( "\n" );
}
}
}
int defeat ()//失败界面
{
CursorJump ( 10 , 50 );
printf ( "\n\t\t\t—————————游戏失败—————————\n" );
printf ( "\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t|其他键继续游戏 |\n" );
printf ( "\t\t\t—————————游戏失败—————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
else
{
MAX_integral = integral;//保存最大积分
return 5;
}
}
int main ()
{
HideCursor ( );//隐藏光标
game_Begin:
system ( "cls" );
score = ( game_Integral * ) malloc ( sizeof ( game_Integral ) );//动态分配光标内存
head = ( snake_head * ) malloc ( sizeof ( snake_head ) );// 动态分配蛇头内存
body = ( snake_body * ) malloc ( sizeof ( snake_body ) );// 动态分配蛇头内存
score -> x = 1;//积分横坐标
score -> y = map_Longitudinal;//积分纵坐标
score -> MAX_x = map_across - 13;//最大积分横坐标
srand ( time ( NULL ) );//设置随机数
char direction_test = 'd';//方向接收
char direction = 'd';//方向
int move_x = 0;//更新移动所产生的横坐标
int move_y = 0;//更新移动所产生的纵坐标
int pick = 0;//接收是否重开游戏
print_map ( );//打印当前地图
print_score ( );//打印积分
initial_snake ( );//生成蛇
food_map ( );//在动图上生成食物
while ( 1 )
{
if ( _kbhit ( ) )//接收用户输入
{
direction_test = _getch ( );
if ( direction_test == 'W' || direction_test == 'w' || direction_test == 'S' || direction_test == 's' ||
direction_test == 'A' || direction_test == 'a' || direction_test == 'D' ||
direction_test == 'd' )//判断方向对不对
{
direction = direction_test;//更新移动方向
}
}
//判断移动的坐标
if ( direction == 'W' || direction == 'w' )//判断向上
{
if ( move_y == 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y - 1 ][ head -> x ] == mark_snake ||
map[ head -> y - 1 ][ head -> x ] == mark_wall )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y - 1 ][ head -> x ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
}
else if ( direction == 'S' || direction == 's' )//判断向下
{
if ( move_y == - 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y + 1 ][ head -> x ] == mark_wall ||
map[ head -> y + 1 ][ head -> x ] == mark_snake )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y + 1 ][ head -> x ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
}
else if ( direction == 'A' || direction == 'a' )//判断向左
{
if ( move_x == 1 )
{
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y ][ head -> x - 1 ] == mark_wall ||
map[ head -> y ][ head -> x - 1 ] == mark_snake )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y ][ head -> x - 1 ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
else if ( direction == 'D' || direction == 'd' )//判断右
{
if ( move_x == - 1 )
{
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y ][ head -> x + 1 ] == mark_wall ||
map[ head -> y ][ head -> x + 1 ] == mark_snake )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y ][ head -> x + 1 ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
if ( pick == 5 || direction_test == 'R' || direction_test == 'r' )//判断是否重开游戏
{
system ( "cls" );
integral = 0;//重置玩家积分
free ( score );
free ( head );
free ( body );
goto game_Begin;
}
move ( move_x , move_y );//将坐标移动
Sleep ( 80 );//停顿一秒
}
return 0;
#include <stdio.h>
#include <unistd.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define map_Longitudinal 27//地图高度
#define map_across 102//地图宽度
int integral = 0;//玩家积分
int MAX_integral = 0;//最高积分
int pick_food = 1;//判断地图上有没有食物
int map[map_Longitudinal][map_across];//储存地图状态
#define mark_NULL 0//标记空
#define mark_snake 1//标记蛇
#define mark_wall 2//标记墙
#define mark_food 3//标记为食物
void color ( int c )//颜色设置
{
SetConsoleTextAttribute ( GetStdHandle ( STD_OUTPUT_HANDLE ) , c ); //颜色设置
//注SetConsoleTextAttribute是一个API应用程序编程接口
}
typedef struct
{
int y;//纵坐标
int x;//横坐标
int MAX_x;//横坐标
} game_Integral;//得分
game_Integral * score;//全局声明得分
typedef struct
{
int y;//纵坐标
int x;//横坐标
} snake_head;//蛇头
snake_head * head;//全局声明蛇头
typedef struct
{
int y[99];//纵坐标
int x[99];//横坐标
int length;//蛇身体长度
} snake_body;//蛇身
snake_body * body;//全局声明蛇身
void HideCursor ()//隐藏光标
{
CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
curInfo . dwSize = 1; //如果没赋值的话,光标隐藏无效
curInfo . bVisible = FALSE; //将光标设置为不可见
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE ); //获取控制台句柄
SetConsoleCursorInfo ( handle , & curInfo ); //设置光标信息
}
void CursorJump ( int y , int x )//光标跳转
{
COORD pos; //定义光标位置的结构体变量
pos . X = x; //横坐标
pos . Y = y; //纵坐标
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE ); //获取控制台句柄
SetConsoleCursorPosition ( handle , pos ); //设置光标位置
}
void print_score ()//打印积分
{
color ( 14 );
CursorJump ( score -> y , score -> x );
printf ( "\n当前积分为%d分\n" , integral );
CursorJump ( score -> y + 1 , score -> MAX_x );
printf ( "最高积分为%d分\n" , MAX_integral );
}
void food_map ()//在动图上生成食物
{
int i = rand ( ) % map_Longitudinal;//随机食物纵坐标
int j = rand ( ) % map_across;//随机食物横坐标
int random = rand ( ) % 14 + 1;//随机生成颜色
if ( map[ i ][ j ] == mark_NULL )//监测到有物体就重新生成
{
map[ i ][ j ] = mark_food; // 正确标记食物
color ( random );
CursorJump ( i , j );
printf ( "" );
}
else
{
food_map ( );
}
}
void move ( int move_x , int move_y )//移动逻辑
{
color ( 10 ); //颜色设置为绿色
if ( pick_food == 0 )
{
body -> x[ body -> length ] = body -> x[ body -> length - 1 ];
body -> y[ body -> length ] = body -> y[ body -> length - 1 ];
map[ body -> y[ body -> length ] ][ body -> x[ body -> length ] ] = mark_snake;//标记蛇
body -> length += 1;//增加蛇身体长度
integral += 10;//增加积分
}
//将最后一个取消
map[ body -> y[ body -> length - 1 ] ][ body -> x[ body -> length - 1 ] ] = mark_NULL;//标记为空
CursorJump ( body -> y[ body -> length - 1 ] , body -> x[ body -> length - 1 ] );
printf ( " " );
//更新蛇身坐标
for ( int i = body -> length - 1 ; i > 0 ; -- i )
{
body -> x[ i ] = body -> x[ i - 1 ];
body -> y[ i ] = body -> y[ i - 1 ];
}
body -> x[ 0 ] = head -> x;
body -> y[ 0 ] = head -> y;
//将蛇头原来的坐标替换为身体
CursorJump ( head -> y , head -> x );
printf ( "" );
//更新蛇头坐标
head -> x += move_x;
head -> y += move_y;
//把蛇头的坐标在地图更新
map[ head -> y ][ head -> x ] = mark_snake;//标记蛇
CursorJump ( head -> y , head -> x );
printf ( "" );
if ( pick_food == 0 )
{
food_map ( );
print_score ( );//重新打印积分
pick_food = 1;
}
}
void Begin ()//开始界面
{
printf ( "\n\n\n\n\n\n\n\n\t\t\t\t\t——————————贪吃蛇——————————\n" );
printf ( "\t\t\t\t\t|使用WSAD进行上下左右移动|\n" );
printf ( "\t\t\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t\t\t|回车进入游戏 |\n" );
printf ( "\t\t\t\t\t——————————贪吃蛇——————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
}
void initial_snake ()//初始蛇
{
color ( 10 ); //颜色设置为绿色
//初始化蛇头
head -> x = 10;
head -> y = 10;
//初始化蛇身
body -> x[ 1 ] = 9;
body -> y[ 1 ] = 10;
body -> x[ 0 ] = 8;
body -> y[ 0 ] = 10;
body -> length = 2;
//生成蛇的图像
//蛇头
map[ head -> y ][ head -> x ] = mark_snake;//标记蛇
CursorJump ( head -> y , head -> x );
printf ( "" );
//蛇身
for ( int i = body -> length - 1 ; i >= 0 ; -- i )
{
map[ body -> y[ i ] ][ body -> x[ i ] ] = mark_snake;//标记蛇
CursorJump ( body -> y[ i ] , body -> x[ i ] );
printf ( "" );
}
}
void print_map ()//初始地图
{
color ( 12 );
for ( int i = 0 ; i < map_Longitudinal ; ++ i )
{
if ( i == 0 || i == map_Longitudinal - 1 )
{
for ( int j = 0 ; j < map_across ; ++ j )
{
//打印墙并且标记状态为墙
map[ i ][ j ] = mark_wall;
printf ( "" );
}
printf ( "\n" );
}
else
{
for ( int j = 0 ; j < map_across ; ++ j )
{
if ( j == 0 || j == map_across - 1 )//打印边界
{
//打印墙并且标记状态为墙
map[ i ][ j ] = mark_wall;
printf ( "" );
}
else
{
map[ i ][ j ] = mark_NULL;//标记为空
printf ( " " );//输出地图
}
}
printf ( "\n" );
}
}
}
int defeat ()//失败界面
{
CursorJump ( 10 , 50 );
printf ( "\n\t\t\t—————————游戏失败—————————\n" );
printf ( "\t\t\t|按ESC退出游戏 |\n" );
printf ( "\t\t\t|其他键继续游戏 |\n" );
printf ( "\t\t\t—————————游戏失败—————————\n" );
int a = _getch ( );
if ( a == 27 )
{
exit ( 0 );
}
else
{
MAX_integral = integral;//保存最大积分
return 5;
}
}
int main ()
{
HideCursor ( );//隐藏光标
game_Begin:
system ( "cls" );
score = ( game_Integral * ) malloc ( sizeof ( game_Integral ) );//动态分配光标内存
head = ( snake_head * ) malloc ( sizeof ( snake_head ) );// 动态分配蛇头内存
body = ( snake_body * ) malloc ( sizeof ( snake_body ) );// 动态分配蛇头内存
score -> x = 1;//积分横坐标
score -> y = map_Longitudinal;//积分纵坐标
score -> MAX_x = map_across - 13;//最大积分横坐标
srand ( time ( NULL ) );//设置随机数
char direction_test = 'd';//方向接收
char direction = 'd';//方向
int move_x = 0;//更新移动所产生的横坐标
int move_y = 0;//更新移动所产生的纵坐标
int pick = 0;//接收是否重开游戏
print_map ( );//打印当前地图
print_score ( );//打印积分
initial_snake ( );//生成蛇
food_map ( );//在动图上生成食物
while ( 1 )
{
if ( _kbhit ( ) )//接收用户输入
{
direction_test = _getch ( );
if ( direction_test == 'W' || direction_test == 'w' || direction_test == 'S' || direction_test == 's' ||
direction_test == 'A' || direction_test == 'a' || direction_test == 'D' ||
direction_test == 'd' )//判断方向对不对
{
direction = direction_test;//更新移动方向
}
}
//判断移动的坐标
if ( direction == 'W' || direction == 'w' )//判断向上
{
if ( move_y == 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y - 1 ][ head -> x ] == mark_snake ||
map[ head -> y - 1 ][ head -> x ] == mark_wall )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y - 1 ][ head -> x ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
}
else if ( direction == 'S' || direction == 's' )//判断向下
{
if ( move_y == - 1 )
{
move_x = 0;//更新移动所产生的横坐标
move_y = - 1;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y + 1 ][ head -> x ] == mark_wall ||
map[ head -> y + 1 ][ head -> x ] == mark_snake )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y + 1 ][ head -> x ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = 0;//更新移动所产生的横坐标
move_y = 1;//更新移动所产生的纵坐标
}
}
else if ( direction == 'A' || direction == 'a' )//判断向左
{
if ( move_x == 1 )
{
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y ][ head -> x - 1 ] == mark_wall ||
map[ head -> y ][ head -> x - 1 ] == mark_snake )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y ][ head -> x - 1 ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
else if ( direction == 'D' || direction == 'd' )//判断右
{
if ( move_x == - 1 )
{
move_x = - 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
else
{
if ( map[ head -> y ][ head -> x + 1 ] == mark_wall ||
map[ head -> y ][ head -> x + 1 ] == mark_snake )//判断有没有失败
{
pick = defeat ( );
}
if ( map[ head -> y ][ head -> x + 1 ] == mark_food )
{
pick_food = 0;//提示食物没有了
}
move_x = 1;//更新移动所产生的横坐标
move_y = 0;//更新移动所产生的纵坐标
}
}
if ( pick == 5 || direction_test == 'R' || direction_test == 'r' )//判断是否重开游戏
{
system ( "cls" );
integral = 0;//重置玩家积分
free ( score );
free ( head );
free ( body );
goto game_Begin;
}
move ( move_x , move_y );//将坐标移动
Sleep ( 80 );//停顿一秒
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,153 +1,153 @@
#include<stdio.h>
#include<stdlib.h>
int main ()
{
double a , b , c , e , f , g , h; ///本金,年利率.年份,利息,本利,取钱,case里面的变量,i
int d; //获取用户需要进入的模式
//开始界面
printf ( "简易atm机 \n" );
printf ( "--------------------- \n" ); //用于分割
//本金
printf ( "请输入你的本金:" );
while ( scanf ( "%lf" , & a ) != 1 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
//年利率
printf ( "请输入你的年利率(不用输入%%):" );
while ( scanf ( "%lf" , & b ) != 1 || b <= 0 ) //判断是否为合法数字
{
printf ( "请输入合法的年利率:" );
while ( getchar ( ) != '\n' );
}
//年份
printf ( "请输入你的年份:" );
while ( scanf ( "%lf" , & c ) != 1 || c <= 0 ) //判断是否为合法数字
{
printf ( "请输入合理的年份:" );
while ( getchar ( ) != '\n' );
}
system ( "cls" ); // windows清屏命令,如果其他系统报错删除此行或注释掉
//system("clear"); //Linux和macOS清屏命令
while ( 1 )
{
e = a * b * c / 100; //利息
f = a + e; //本利
printf ( "存入本金为%.3lf \n" , a );
printf ( "当前利率为%.3lf%% \n" , b );
printf ( "当前存了%.0lf年 \n" , c );
printf ( "获得的利息为%.3lf \n" , e );
printf ( "余额为%.3lf \n" , f );
printf ( "--------------------- \n" ); //用于分割
printf ( "请输入对应的数字进入对应的模式 \n" );
printf ( "0.退出 \n" );
printf ( "1.存钱 \n" );
printf ( "2.取钱 \n" );
printf ( "3.增加年份 \n" );
printf ( "4.减少年份 \n" );
printf ( "5.增加年利率 \n" );
printf ( "6.减少年利率 \n" );
printf ( "请输入对应的数字进入需要的模式:" );
while ( scanf ( "%d" , & d ) < 0 || d > 4 ) //判断是否为合适数字
{
printf ( "请输入对应的数字:" );
while ( getchar ( ) != '\n' );
}
switch ( d )
{
case 0:
{
return 1;
}
case 1:
{
printf ( "请输入你需要存入多少钱:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
a += h;
system ( "cls" ); // windows清屏命令
break;
}
case 2:
{
printf ( "请输入你需要取出多少钱:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 || h > a ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
a -= h;
system ( "cls" ); // windows清屏命令
break;
}
case 3:
{
printf ( "请输入你需要增加多少年:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
c += h;
system ( "cls" ); // windows清屏命令
break;
}
case 4:
{
printf ( "请输入你需要减少多少年:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 || h > a ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
c -= h;
system ( "cls" ); // windows清屏命令
break;
}
case 5:
{
printf ( "请输入你需要增加多少年利率(不用输入%%):" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
b += h;
system ( "cls" ); // windows清屏命令
break;
}
case 6:
{
printf ( "请输入你需要减少多少年利率(不用输入%%):" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 || h > a ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
b -= h;
system ( "cls" ); // windows清屏命令
break;
}
}
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main ()
{
double a , b , c , e , f , g , h; ///本金,年利率.年份,利息,本利,取钱,case里面的变量,i
int d; //获取用户需要进入的模式
//开始界面
printf ( "简易atm机 \n" );
printf ( "--------------------- \n" ); //用于分割
//本金
printf ( "请输入你的本金:" );
while ( scanf ( "%lf" , & a ) != 1 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
//年利率
printf ( "请输入你的年利率(不用输入%%):" );
while ( scanf ( "%lf" , & b ) != 1 || b <= 0 ) //判断是否为合法数字
{
printf ( "请输入合法的年利率:" );
while ( getchar ( ) != '\n' );
}
//年份
printf ( "请输入你的年份:" );
while ( scanf ( "%lf" , & c ) != 1 || c <= 0 ) //判断是否为合法数字
{
printf ( "请输入合理的年份:" );
while ( getchar ( ) != '\n' );
}
system ( "cls" ); // windows清屏命令,如果其他系统报错删除此行或注释掉
//system("clear"); //Linux和macOS清屏命令
while ( 1 )
{
e = a * b * c / 100; //利息
f = a + e; //本利
printf ( "存入本金为%.3lf \n" , a );
printf ( "当前利率为%.3lf%% \n" , b );
printf ( "当前存了%.0lf年 \n" , c );
printf ( "获得的利息为%.3lf \n" , e );
printf ( "余额为%.3lf \n" , f );
printf ( "--------------------- \n" ); //用于分割
printf ( "请输入对应的数字进入对应的模式 \n" );
printf ( "0.退出 \n" );
printf ( "1.存钱 \n" );
printf ( "2.取钱 \n" );
printf ( "3.增加年份 \n" );
printf ( "4.减少年份 \n" );
printf ( "5.增加年利率 \n" );
printf ( "6.减少年利率 \n" );
printf ( "请输入对应的数字进入需要的模式:" );
while ( scanf ( "%d" , & d ) < 0 || d > 4 ) //判断是否为合适数字
{
printf ( "请输入对应的数字:" );
while ( getchar ( ) != '\n' );
}
switch ( d )
{
case 0:
{
return 1;
}
case 1:
{
printf ( "请输入你需要存入多少钱:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
a += h;
system ( "cls" ); // windows清屏命令
break;
}
case 2:
{
printf ( "请输入你需要取出多少钱:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 || h > a ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
a -= h;
system ( "cls" ); // windows清屏命令
break;
}
case 3:
{
printf ( "请输入你需要增加多少年:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
c += h;
system ( "cls" ); // windows清屏命令
break;
}
case 4:
{
printf ( "请输入你需要减少多少年:" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 || h > a ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
c -= h;
system ( "cls" ); // windows清屏命令
break;
}
case 5:
{
printf ( "请输入你需要增加多少年利率(不用输入%%):" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
b += h;
system ( "cls" ); // windows清屏命令
break;
}
case 6:
{
printf ( "请输入你需要减少多少年利率(不用输入%%):" );
while ( scanf ( "%lf" , & h ) != 1 || h < 0 || h > a ) //判断是否为合法数字
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' );
}
b -= h;
system ( "cls" ); // windows清屏命令
break;
}
}
}
return 0;
}

View File

@ -1,467 +1,467 @@
#include<stdio.h>
#include<stdlib.h>
int main ()
{
//初始化
int account_1 , password_1 , password_2 = 0 , password_3 = 0 , account_2 = 0 , password_4 = 0; //账号;登录密码,取款密码,登录检查密码,检查登录账户,修改密码判断是不是6位
char tab_1; //用户是否同意进入
int tab_a = 0 , tab_b , tab_c , tab_d = 0 , tab_e , tab_f; //判断取款密码是否为6位数.判断取款密码是否为6位数,判断进入登录还是管理员,判断是否进入账户主页主页;账户主页选项;判断用户修改是否输入正确
int administration_password , administration_a; //管理员密码,判断管理员选项
double interest = 0 , capital = 10000 , money = 0 , interest_rate = 0.0175 , year = 0 , capital_1 = 0; //利息,本金,变动的钱,利率,年份,预测本金
//注册账户
printf ( "第一次使用需要注册账户 \n" );
printf ( "不同意输入N,输入其他代表同意 \n:" );
//获取用户是否同意进入
tab_1 = getchar ( );
if ( tab_1 == 'n' || tab_1 == 'N' )
{
return 1;
}
while ( getchar ( ) != '\n' ); //清楚缓存
//注册登录账户
printf ( "账户名(只支持数字):" );
while ( scanf ( "%d" , & account_1 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
while ( getchar ( ) != '\n' ); //清楚缓存
//注册登录密码
printf ( "登录密码(只支持数字):" );
while ( scanf ( "%d" , & password_1 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
while ( getchar ( ) != '\n' ); //清楚缓存
//注册取款密码
//注册取款密码
printf ( "取款密码(只支持6位数字):" );
while ( password_2 == 0 )
{
//判断是不是输入的数字
while ( scanf ( "%d" , & password_2 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
tab_b = password_2;
//判断是否为6位数
while ( tab_b != 0 )
{
tab_b /= 10;
tab_a ++;
}
if ( tab_a != 6 )
{
printf ( "当前输入%d位,密码是6位数 \n请重新输入:" , tab_a );
password_2 = 0;
tab_a = 0;
continue;
}
if ( tab_a == 6 )
{
break;
}
}
while ( getchar ( ) != '\n' ); //清楚缓存
//提示用户输入成功
printf ( "创建成功 \n" );
printf ( "账户名:%d \n" , account_1 );
printf ( "密码:%d \n" , password_1 );
printf ( "密码:%d \n" , password_2 );
printf ( "初始金额为%lf \n" , capital );
//此层循环为主页面开始
while ( 1 )
{
printf ( "----银行主页----\n" );
printf ( "0.退出程序 \n" );
printf ( "1.登录银行账户 \n" );
printf ( "请输入数字:" );
scanf ( "%d" , & tab_c );
printf ( "----银行主页----\n" );
while ( getchar ( ) != '\n' ); //清楚缓存
//0退出
if ( tab_c == 0 )
{
printf ( "欢迎下次使用" );
return 1;
}
//获取是否输入正确
if ( tab_c != 0 && tab_c != 1 && tab_c != 2 )
{
printf ( "输入错误请重新输入 \n" );
continue;
}
//银行主页开始
while ( tab_c == 1 )
{
printf ( "需要登陆账号 \n" );
//获取用户账号
printf ( "请输入账号:" );
scanf ( "%d" , & account_2 );
while ( account_1 != account_2 ) //判断账户是否正确
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入正确的账号:" );
scanf ( "%d" , & account_2 );
}
//获取用密码
printf ( "请输入密码:" );
scanf ( "%d" , & password_3 );
while ( password_1 != password_3 ) //判断密码是否正确
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入正确的密码:" );
scanf ( "%d" , & password_3 );
}
// 正确的账号和密码
printf ( "登录成功!\n" );
tab_d = 1; //进入主页
//此层输出账户主页
while ( tab_d == 1 )
{
printf ( "----账户主页----\n" );
printf ( "0.退出程序 \n" );
printf ( "1.退出账户 \n" );
printf ( "2.存钱 \n" );
printf ( "3.取钱 \n" );
printf ( "4.查看余额 \n" );
printf ( "5.预测未来存款(当前利率为%.3lf) \n" , interest_rate );
printf ( "6.修改账号 \n" );
printf ( "7.修改密码 \n" );
printf ( "8.修改取款密码 \n" );
printf ( "请输入数字:" );
scanf ( "%d" , & tab_e );
printf ( "----账户主页----\n" );
while ( getchar ( ) != '\n' ); //清楚缓存
//重置判断
tab_f = 0;
tab_a = 0; //取款数字是否为6位
//选择开始
switch ( tab_e )
{
case 0:
{
printf ( "欢迎下次使用" );
return 1;
}
case 1:
{
tab_d = 0; //使不进入其他循环
tab_c = 999; //使不进入其他循环
printf ( "退出成功\n" );
while ( getchar ( ) != '\n' ); //清楚缓存
break;
}
case 2:
{
printf ( "请输入需要存入多少钱:" );
while ( scanf ( "%lf" , & money ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
capital += money;
break;
}
case 3:
{
printf ( "请输入当前密码或取款密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 || password_3 != password_2 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "当密码错误,请重新输入:" );
continue;
}
printf ( "请输入需要取出多少钱:" );
while ( scanf ( "%lf" , & money ) != 1 || money > capital )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或本金不足,请重新输入:" );
continue;
}
capital -= money;
break;
}
case 4:
{
printf ( "当前余额为%.3lf: \n" , capital );
break;
}
case 5:
{
printf ( "请输入预测多少年后:" );
while ( scanf ( "%lf" , & year ) != 1 || year < 0 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
double interest = capital * interest_rate * year; // 计算利息
double capital_1 = capital + interest; // 计算预测余额
printf ( "预测%.0lf年后获得\n" , year );
printf ( "利息%.3lf\n" , interest );
printf ( "余额%.3lf \n" , capital_1 );
}
case 6:
{
//验证用户开始
while ( tab_f == 0 )
{
printf ( "需要验证用户\n输入0退出\n" );
printf ( "请输入当前登录账户名或取款密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或密码错误,请重新输入:" );
continue;
}
//检查是否退出
if ( password_3 == 0 )
{
printf ( "退出成功" );
tab_f = 1;
break;
}
//输入成功退出
if ( password_3 == password_2 || password_3 == account_1 )
{
printf ( "验证成功 \n" );
tab_f = 1;
break;
} else
{
printf ( "输入错误请重新输入 \n" );
continue;
}
}//验证用户结束
//修改新账户
while ( tab_a == 0 )
{
printf ( "请输入新账户名:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "非法数字,请重新输入:" );
continue;
}
//二次确认账户
printf ( "请二次输入你的账户名:" );
while ( scanf ( "%d" , & password_4 ) != 1 || password_4 != password_3 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "账户名不一样,请重新输入:" );
continue;
}
//退出循环
break;
}//修改新的账户结束
account_1 = password_3;
printf ( "修改账号成功" );
printf ( "当前账户名是%d" , account_1 );
break;
}
case 7:
{
//验证用户开始
while ( tab_f == 0 )
{
printf ( "需要验证用户\n输入0退出\n" );
printf ( "请输入当前登录密码或取款密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或密码错误,请重新输入:" );
continue;
}
//检查是否退出
if ( password_3 == 0 )
{
printf ( "退出成功" );
tab_f = 1;
break;
}
//输入成功退出
if ( password_3 == password_2 || password_3 == password_1 )
{
printf ( "验证成功 \n" );
tab_f = 1;
break;
} else
{
printf ( "输入错误请重新输入 \n" );
continue;
}
}//验证用户结束
//修改新密码
while ( tab_a == 0 )
{
printf ( "请输入新密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "非法数字,请重新输入:" );
continue;
}
//二次确认密码
printf ( "请二次输入你的密码:" );
while ( scanf ( "%d" , & password_4 ) != 1 || password_4 != password_3 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "密码不一样,请重新输入:" );
continue;
}
//退出循环
break;
}//修改新的密码结束
password_1 = password_3;
printf ( "修改账户密码成功" );
printf ( "当前密码为:%d" , password_1 );
break;
}
case 8:
{
//验证用户开始
while ( tab_f == 0 )
{
printf ( "需要验证用户\n输入0退出\n" );
printf ( "请输入当前取款密码或账户登录密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或密码错误,请重新输入:" );
continue;
}
//检查是否退出
if ( password_3 == 0 )
{
printf ( "退出成功" );
tab_f = 1;
break;
}
//输入成功退出
if ( password_3 == password_2 || password_3 == password_1 )
{
printf ( "验证成功 \n" );
tab_f = 1;
break;
} else
{
printf ( "输入错误请重新输入 \n" );
continue;
}
}//验证用户结束
//修改新密码
while ( tab_a != 6 )
{
printf ( "请输入新密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "非法数字,请重新输入:" );
continue;
}
//判断是否为6位数
tab_a = 0;//初始化判断
//为了防止刚刚的密码没有了
password_4 = password_3;
while ( password_4 != 0 )
{
password_4 /= 10;
tab_a ++;
}
if ( tab_a != 6 )
{
printf ( "当前输入%d位,密码是6位数 \n请重新输入\n" , tab_a );
continue;
}
if ( tab_a == 6 )
{
printf ( "请二次输入你的密码:" );
while ( scanf ( "%d" , & password_4 ) != 1 || password_4 != password_3 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "密码不一样,请重新输入:" );
continue;
}
if ( password_4 == password_3 )
{
break;
}
break;
}//修改新的密码结束
}
password_2 = password_3;
printf ( "修改取款密码成功" );
printf ( "当前密码为:%d \n" , password_2 );
break;
}
default: //输入了其他
{
printf ( "输入错误,请重新输入 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
break;
}
}//选择结束
}
}//银行主页结束
}//此层循环为主页面结束
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main ()
{
//初始化
int account_1 , password_1 , password_2 = 0 , password_3 = 0 , account_2 = 0 , password_4 = 0; //账号;登录密码,取款密码,登录检查密码,检查登录账户,修改密码判断是不是6位
char tab_1; //用户是否同意进入
int tab_a = 0 , tab_b , tab_c , tab_d = 0 , tab_e , tab_f; //判断取款密码是否为6位数.判断取款密码是否为6位数,判断进入登录还是管理员,判断是否进入账户主页主页;账户主页选项;判断用户修改是否输入正确
int administration_password , administration_a; //管理员密码,判断管理员选项
double interest = 0 , capital = 10000 , money = 0 , interest_rate = 0.0175 , year = 0 , capital_1 = 0; //利息,本金,变动的钱,利率,年份,预测本金
//注册账户
printf ( "第一次使用需要注册账户 \n" );
printf ( "不同意输入N,输入其他代表同意 \n:" );
//获取用户是否同意进入
tab_1 = getchar ( );
if ( tab_1 == 'n' || tab_1 == 'N' )
{
return 1;
}
while ( getchar ( ) != '\n' ); //清楚缓存
//注册登录账户
printf ( "账户名(只支持数字):" );
while ( scanf ( "%d" , & account_1 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
while ( getchar ( ) != '\n' ); //清楚缓存
//注册登录密码
printf ( "登录密码(只支持数字):" );
while ( scanf ( "%d" , & password_1 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
while ( getchar ( ) != '\n' ); //清楚缓存
//注册取款密码
//注册取款密码
printf ( "取款密码(只支持6位数字):" );
while ( password_2 == 0 )
{
//判断是不是输入的数字
while ( scanf ( "%d" , & password_2 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
tab_b = password_2;
//判断是否为6位数
while ( tab_b != 0 )
{
tab_b /= 10;
tab_a ++;
}
if ( tab_a != 6 )
{
printf ( "当前输入%d位,密码是6位数 \n请重新输入:" , tab_a );
password_2 = 0;
tab_a = 0;
continue;
}
if ( tab_a == 6 )
{
break;
}
}
while ( getchar ( ) != '\n' ); //清楚缓存
//提示用户输入成功
printf ( "创建成功 \n" );
printf ( "账户名:%d \n" , account_1 );
printf ( "密码:%d \n" , password_1 );
printf ( "密码:%d \n" , password_2 );
printf ( "初始金额为%lf \n" , capital );
//此层循环为主页面开始
while ( 1 )
{
printf ( "----银行主页----\n" );
printf ( "0.退出程序 \n" );
printf ( "1.登录银行账户 \n" );
printf ( "请输入数字:" );
scanf ( "%d" , & tab_c );
printf ( "----银行主页----\n" );
while ( getchar ( ) != '\n' ); //清楚缓存
//0退出
if ( tab_c == 0 )
{
printf ( "欢迎下次使用" );
return 1;
}
//获取是否输入正确
if ( tab_c != 0 && tab_c != 1 && tab_c != 2 )
{
printf ( "输入错误请重新输入 \n" );
continue;
}
//银行主页开始
while ( tab_c == 1 )
{
printf ( "需要登陆账号 \n" );
//获取用户账号
printf ( "请输入账号:" );
scanf ( "%d" , & account_2 );
while ( account_1 != account_2 ) //判断账户是否正确
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入正确的账号:" );
scanf ( "%d" , & account_2 );
}
//获取用密码
printf ( "请输入密码:" );
scanf ( "%d" , & password_3 );
while ( password_1 != password_3 ) //判断密码是否正确
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入正确的密码:" );
scanf ( "%d" , & password_3 );
}
// 正确的账号和密码
printf ( "登录成功!\n" );
tab_d = 1; //进入主页
//此层输出账户主页
while ( tab_d == 1 )
{
printf ( "----账户主页----\n" );
printf ( "0.退出程序 \n" );
printf ( "1.退出账户 \n" );
printf ( "2.存钱 \n" );
printf ( "3.取钱 \n" );
printf ( "4.查看余额 \n" );
printf ( "5.预测未来存款(当前利率为%.3lf) \n" , interest_rate );
printf ( "6.修改账号 \n" );
printf ( "7.修改密码 \n" );
printf ( "8.修改取款密码 \n" );
printf ( "请输入数字:" );
scanf ( "%d" , & tab_e );
printf ( "----账户主页----\n" );
while ( getchar ( ) != '\n' ); //清楚缓存
//重置判断
tab_f = 0;
tab_a = 0; //取款数字是否为6位
//选择开始
switch ( tab_e )
{
case 0:
{
printf ( "欢迎下次使用" );
return 1;
}
case 1:
{
tab_d = 0; //使不进入其他循环
tab_c = 999; //使不进入其他循环
printf ( "退出成功\n" );
while ( getchar ( ) != '\n' ); //清楚缓存
break;
}
case 2:
{
printf ( "请输入需要存入多少钱:" );
while ( scanf ( "%lf" , & money ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
capital += money;
break;
}
case 3:
{
printf ( "请输入当前密码或取款密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 || password_3 != password_2 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "当密码错误,请重新输入:" );
continue;
}
printf ( "请输入需要取出多少钱:" );
while ( scanf ( "%lf" , & money ) != 1 || money > capital )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或本金不足,请重新输入:" );
continue;
}
capital -= money;
break;
}
case 4:
{
printf ( "当前余额为%.3lf: \n" , capital );
break;
}
case 5:
{
printf ( "请输入预测多少年后:" );
while ( scanf ( "%lf" , & year ) != 1 || year < 0 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "请输入合法的数字:" );
continue;
}
double interest = capital * interest_rate * year; // 计算利息
double capital_1 = capital + interest; // 计算预测余额
printf ( "预测%.0lf年后获得\n" , year );
printf ( "利息%.3lf\n" , interest );
printf ( "余额%.3lf \n" , capital_1 );
}
case 6:
{
//验证用户开始
while ( tab_f == 0 )
{
printf ( "需要验证用户\n输入0退出\n" );
printf ( "请输入当前登录账户名或取款密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或密码错误,请重新输入:" );
continue;
}
//检查是否退出
if ( password_3 == 0 )
{
printf ( "退出成功" );
tab_f = 1;
break;
}
//输入成功退出
if ( password_3 == password_2 || password_3 == account_1 )
{
printf ( "验证成功 \n" );
tab_f = 1;
break;
} else
{
printf ( "输入错误请重新输入 \n" );
continue;
}
}//验证用户结束
//修改新账户
while ( tab_a == 0 )
{
printf ( "请输入新账户名:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "非法数字,请重新输入:" );
continue;
}
//二次确认账户
printf ( "请二次输入你的账户名:" );
while ( scanf ( "%d" , & password_4 ) != 1 || password_4 != password_3 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "账户名不一样,请重新输入:" );
continue;
}
//退出循环
break;
}//修改新的账户结束
account_1 = password_3;
printf ( "修改账号成功" );
printf ( "当前账户名是%d" , account_1 );
break;
}
case 7:
{
//验证用户开始
while ( tab_f == 0 )
{
printf ( "需要验证用户\n输入0退出\n" );
printf ( "请输入当前登录密码或取款密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或密码错误,请重新输入:" );
continue;
}
//检查是否退出
if ( password_3 == 0 )
{
printf ( "退出成功" );
tab_f = 1;
break;
}
//输入成功退出
if ( password_3 == password_2 || password_3 == password_1 )
{
printf ( "验证成功 \n" );
tab_f = 1;
break;
} else
{
printf ( "输入错误请重新输入 \n" );
continue;
}
}//验证用户结束
//修改新密码
while ( tab_a == 0 )
{
printf ( "请输入新密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "非法数字,请重新输入:" );
continue;
}
//二次确认密码
printf ( "请二次输入你的密码:" );
while ( scanf ( "%d" , & password_4 ) != 1 || password_4 != password_3 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "密码不一样,请重新输入:" );
continue;
}
//退出循环
break;
}//修改新的密码结束
password_1 = password_3;
printf ( "修改账户密码成功" );
printf ( "当前密码为:%d" , password_1 );
break;
}
case 8:
{
//验证用户开始
while ( tab_f == 0 )
{
printf ( "需要验证用户\n输入0退出\n" );
printf ( "请输入当前取款密码或账户登录密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "数字不合法或密码错误,请重新输入:" );
continue;
}
//检查是否退出
if ( password_3 == 0 )
{
printf ( "退出成功" );
tab_f = 1;
break;
}
//输入成功退出
if ( password_3 == password_2 || password_3 == password_1 )
{
printf ( "验证成功 \n" );
tab_f = 1;
break;
} else
{
printf ( "输入错误请重新输入 \n" );
continue;
}
}//验证用户结束
//修改新密码
while ( tab_a != 6 )
{
printf ( "请输入新密码:" );
while ( scanf ( "%d" , & password_3 ) != 1 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "非法数字,请重新输入:" );
continue;
}
//判断是否为6位数
tab_a = 0;//初始化判断
//为了防止刚刚的密码没有了
password_4 = password_3;
while ( password_4 != 0 )
{
password_4 /= 10;
tab_a ++;
}
if ( tab_a != 6 )
{
printf ( "当前输入%d位,密码是6位数 \n请重新输入\n" , tab_a );
continue;
}
if ( tab_a == 6 )
{
printf ( "请二次输入你的密码:" );
while ( scanf ( "%d" , & password_4 ) != 1 || password_4 != password_3 )
{
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "密码不一样,请重新输入:" );
continue;
}
if ( password_4 == password_3 )
{
break;
}
break;
}//修改新的密码结束
}
password_2 = password_3;
printf ( "修改取款密码成功" );
printf ( "当前密码为:%d \n" , password_2 );
break;
}
default: //输入了其他
{
printf ( "输入错误,请重新输入 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
break;
}
}//选择结束
}
}//银行主页结束
}//此层循环为主页面结束
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,18 @@
#include<stdio.h>
#define add(a,b,c)((a)+(a)*(b)*((c)/100))
int main()
{
float a;
float b;
float c;
printf("银行本利计算器 \n");
printf("请输入本金:");
scanf("%f", &a);
printf("请输入年份:");
scanf("%f", &b);
printf("请输入利率(例如2%%只需要填2):");
scanf("%f", &c);
float z = add(a, b, c);
printf("本金加利息为:%f \n", z);
return 0;
}
#include<stdio.h>
#define add(a,b,c)((a)+(a)*(b)*((c)/100))
int main()
{
float a;
float b;
float c;
printf("银行本利计算器 \n");
printf("请输入本金:");
scanf("%f", &a);
printf("请输入年份:");
scanf("%f", &b);
printf("请输入利率(例如2%%只需要填2):");
scanf("%f", &c);
float z = add(a, b, c);
printf("本金加利息为:%f \n", z);
return 0;
}

View File

@ -1,33 +1,33 @@
#include<stdio.h>
int main ()
{
for ( ;; )
{
double x , y , z; //存款金金,存款年份,年利率
int g; //获取退出字符
printf ( "存款本利计算器 \n" );
printf ( "请输入本金:" );
scanf ( "%lf" , & x );
printf ( "请输入年份:" );
scanf ( "%lf" , & y );
printf ( "请输入年利率(不用加%%):" );
scanf ( "%lf" , & z );
printf ( "利息为%lf,本金加利息为%lf \n" , x * y * z / 100 , x + x * y * z / 100 );
while ( getchar ( ) != '\n' ); //读取缓存,到回车结束
printf ( "输入0退出,输入其他继续计算: " );
g = getchar ( );
if ( g == '0' )
{
break;
}
if ( g == '\n' || g != '0' )
{
continue; //重新启动
}
}
return 0;
}
#include<stdio.h>
int main ()
{
for ( ;; )
{
double x , y , z; //存款金金,存款年份,年利率
int g; //获取退出字符
printf ( "存款本利计算器 \n" );
printf ( "请输入本金:" );
scanf ( "%lf" , & x );
printf ( "请输入年份:" );
scanf ( "%lf" , & y );
printf ( "请输入年利率(不用加%%):" );
scanf ( "%lf" , & z );
printf ( "利息为%lf,本金加利息为%lf \n" , x * y * z / 100 , x + x * y * z / 100 );
while ( getchar ( ) != '\n' ); //读取缓存,到回车结束
printf ( "输入0退出,输入其他继续计算: " );
g = getchar ( );
if ( g == '0' )
{
break;
}
if ( g == '\n' || g != '0' )
{
continue; //重新启动
}
}
return 0;
}

View File

@ -1,65 +1,65 @@
#include <stdio.h>
int main ()
{
double x;
double y;
double v = 0;
char z;
printf ( "两位数计算器\n" );
printf ( "请输入运算方式 (+ or - or * or /):" );
scanf ( " %c" , & z );
if ( z != '+' && z != '-' && z != '*' && z != '/' )
{
printf ( "你是脑干缺失,还是不识字,看不到“运算方式”这几个大字?" );
return 1;
}
printf ( "请输入第一位数:" );
scanf ( " %lf" , & x );
if ( x == 0 && x != 0 )
{
printf ( "不知道什么叫数字?\n" );
return 1;
}
printf ( "请输入第二位数:" );
scanf ( " %lf" , & y );
if ( y == 0 && y != 0 )
{
printf ( "不知道什么叫数字?\n" );
return 1;
}
if ( z == '+' )
{
v = x + y;
}
if ( z == '-' )
{
v = x - y;
}
if ( z == '*' )
{
v = x * y;
}
if ( z == '/' )
{
if ( x != 0 )
{
v = x / y;
} else
{
printf ( "分母不能为0 \n" );
return 1;
}
}
printf ( "计算结果为:%lf: \n" , v );
return 0;
}
#include <stdio.h>
int main ()
{
double x;
double y;
double v = 0;
char z;
printf ( "两位数计算器\n" );
printf ( "请输入运算方式 (+ or - or * or /):" );
scanf ( " %c" , & z );
if ( z != '+' && z != '-' && z != '*' && z != '/' )
{
printf ( "你是脑干缺失,还是不识字,看不到“运算方式”这几个大字?" );
return 1;
}
printf ( "请输入第一位数:" );
scanf ( " %lf" , & x );
if ( x == 0 && x != 0 )
{
printf ( "不知道什么叫数字?\n" );
return 1;
}
printf ( "请输入第二位数:" );
scanf ( " %lf" , & y );
if ( y == 0 && y != 0 )
{
printf ( "不知道什么叫数字?\n" );
return 1;
}
if ( z == '+' )
{
v = x + y;
}
if ( z == '-' )
{
v = x - y;
}
if ( z == '*' )
{
v = x * y;
}
if ( z == '/' )
{
if ( x != 0 )
{
v = x / y;
} else
{
printf ( "分母不能为0 \n" );
return 1;
}
}
printf ( "计算结果为:%lf: \n" , v );
return 0;
}

View File

@ -1,78 +1,78 @@
#include <stdio.h>
int main ()
{
//定义函数
int a; //计算模式选择的数字
double x , y; //计算输入的数字, 第一位数字x,第二位数字y
//输出主界面
printf ( "*计算机* \n" );
printf ( "1.加法模式 \n" );
printf ( "2.减法模式 \n" );
printf ( "3.乘法模式 \n" );
printf ( "4.除法模式 \n" );
printf ( "5.退出程序 \n" );
printf ( "输入对应的数字进入对应的模式 \n" );
//获取需要进入的模式
printf ( "输入对应的数字:" );
scanf ( " %d" , & a ); //判断用户输入的数字是否符合条件
if ( a > 5 || a < 1 )
{
printf ( "请输入数字" );
return 1;
}
//计算的第一位数字
printf ( "输入第一位需要计算的数:" );
scanf ( " %lf" , & x ); //判断用户输入的数字是否符合条件
if ( a == 0 && a != 0 )
{
printf ( "请输入数字" );
return 1;
}
//计算的第二位数字
printf ( "输入第二位需要计算的数:" );
scanf ( " %lf" , & y ); //判断用户输入的数字是否符合条件
if ( a == 0 && a != 0 )
{
printf ( "请输入数字" );
return 1;
}
//计算代码块
switch ( a )
{
//加法
case 1:
printf ( "a + b = %lf \n" , x + y );
break;
//减法
case 2:
if ( y = 0 ) //除数不能为0
{
printf ( "除数不能为0" );
return 0;
}
printf ( "a - b = %lf \n" , x - y );
break;
//乘法
case 3:
printf ( "a * b = %lf \n" , x * y );
break;
//除法
case 4:
printf ( "a / b= %lf \n" , x / y );
break;
//输入错误提示
default :
printf ( "请输入正确的数字" );
return 1;
}
return 0;
}
#include <stdio.h>
int main ()
{
//定义函数
int a; //计算模式选择的数字
double x , y; //计算输入的数字, 第一位数字x,第二位数字y
//输出主界面
printf ( "*计算机* \n" );
printf ( "1.加法模式 \n" );
printf ( "2.减法模式 \n" );
printf ( "3.乘法模式 \n" );
printf ( "4.除法模式 \n" );
printf ( "5.退出程序 \n" );
printf ( "输入对应的数字进入对应的模式 \n" );
//获取需要进入的模式
printf ( "输入对应的数字:" );
scanf ( " %d" , & a ); //判断用户输入的数字是否符合条件
if ( a > 5 || a < 1 )
{
printf ( "请输入数字" );
return 1;
}
//计算的第一位数字
printf ( "输入第一位需要计算的数:" );
scanf ( " %lf" , & x ); //判断用户输入的数字是否符合条件
if ( a == 0 && a != 0 )
{
printf ( "请输入数字" );
return 1;
}
//计算的第二位数字
printf ( "输入第二位需要计算的数:" );
scanf ( " %lf" , & y ); //判断用户输入的数字是否符合条件
if ( a == 0 && a != 0 )
{
printf ( "请输入数字" );
return 1;
}
//计算代码块
switch ( a )
{
//加法
case 1:
printf ( "a + b = %lf \n" , x + y );
break;
//减法
case 2:
if ( y = 0 ) //除数不能为0
{
printf ( "除数不能为0" );
return 0;
}
printf ( "a - b = %lf \n" , x - y );
break;
//乘法
case 3:
printf ( "a * b = %lf \n" , x * y );
break;
//除法
case 4:
printf ( "a / b= %lf \n" , x / y );
break;
//输入错误提示
default :
printf ( "请输入正确的数字" );
return 1;
}
return 0;
}

View File

@ -1,70 +1,70 @@
#include<stdio.h>
#include<stdlib.h>
int main ()
{
double x , y;//需要计算的数字
int a;//选择进入模式的数字
while ( 1 )
{
//计算机界面
printf ( "计算器 \n" );
printf ( "1.加法模式 \n" );
printf ( "2.减法模式 \n" );
printf ( "3.乘法模式 \n" );
printf ( "4.除法模式 \n" );
printf ( "5.退出程序 \n" );
//获取用户输入模式的数字
printf ( "请输入对应的数字进入:" );
if ( scanf ( "%d" , & a ) < 1 || a > 5 )
{
printf ( "请输入正确的数字 \n" );
while ( getchar ( ) != '\n' ); //表示循环读入字符,直到读到回车符结束循环
continue;
}
//模式5
if ( a == 5 )
{
exit ( 0 );
}
//获取用户需要计算的第一位数字
printf ( "请输入第一位数:" );
scanf ( "%lf" , & x );
//获取用户需要计算的第二位数字
printf ( "请输入第二位数:" );
scanf ( "%lf" , & y );
//计算程序
switch ( a )
{
//加法
case 1:
printf ( "相加结果为%lf \n" , x + y );
break;
//减法
case 2:
printf ( "相减结果为%lf \n" , x - y );
break;
//乘法
case 3:
printf ( "相乘结果为%lf \n" , x * y );
break;
//除法
case 4:
if ( y == 0 )
{
printf ( "除数不能为0" ); //除数不能为0
continue;
}
printf ( "相除结果为%lf \n" , x / y );
break;
}
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main ()
{
double x , y;//需要计算的数字
int a;//选择进入模式的数字
while ( 1 )
{
//计算机界面
printf ( "计算器 \n" );
printf ( "1.加法模式 \n" );
printf ( "2.减法模式 \n" );
printf ( "3.乘法模式 \n" );
printf ( "4.除法模式 \n" );
printf ( "5.退出程序 \n" );
//获取用户输入模式的数字
printf ( "请输入对应的数字进入:" );
if ( scanf ( "%d" , & a ) < 1 || a > 5 )
{
printf ( "请输入正确的数字 \n" );
while ( getchar ( ) != '\n' ); //表示循环读入字符,直到读到回车符结束循环
continue;
}
//模式5
if ( a == 5 )
{
exit ( 0 );
}
//获取用户需要计算的第一位数字
printf ( "请输入第一位数:" );
scanf ( "%lf" , & x );
//获取用户需要计算的第二位数字
printf ( "请输入第二位数:" );
scanf ( "%lf" , & y );
//计算程序
switch ( a )
{
//加法
case 1:
printf ( "相加结果为%lf \n" , x + y );
break;
//减法
case 2:
printf ( "相减结果为%lf \n" , x - y );
break;
//乘法
case 3:
printf ( "相乘结果为%lf \n" , x * y );
break;
//除法
case 4:
if ( y == 0 )
{
printf ( "除数不能为0" ); //除数不能为0
continue;
}
printf ( "相除结果为%lf \n" , x / y );
break;
}
}
return 0;
}

View File

@ -1,142 +1,142 @@
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int d , e , g; //需要计算的模式,需要计算的数量,判断循环几次,标记是否进行了循环
double a , b , c; //初始化的数字
int f = 1;
while ( 1 )
{
//获取用户需要计算的模式
printf ( " \n" );
printf ( "0.退出计算机 \n" );
printf ( "1.加法模式 \n" );
printf ( "2.减法模式 \n" );
printf ( "3.乘法模式 \n" );
printf ( "4.除法模式 \n" );
//获取用户输入的字符
printf ( "请输入对应的数字进入: " );
scanf ( "%d" , & d );
if ( d > 4 || d < 0 ) //判断数字是否符合条件
{
printf ( "请输入符合条件的数字 \n" );
while ( getchar ( ) != '\n' );
continue;
}
//输入0退出
if ( d == 0 )
{
exit ( 0 );
}
//获取用户需要计算的个数
printf ( "请输入需要的个数:" );
scanf ( "%d" , & e );
if ( e <= 0 ) //判断数字是否合法
{
printf ( "请输入合法的数字 \n" );
while ( getchar ( ) != '\n' );
continue;
}
//加法模式
if ( d == 1 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
++ f;
scanf ( "%lf" , & a );
b += a;
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
//减法模式
if ( d == 2 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
scanf ( "%lf" , & a );
if ( f == 1 )
{
b = a;
} else
{
b -= a;
}
++ f;
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
//乘法模式
if ( d == 3 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
scanf ( "%lf" , & a );
if ( f == 1 )
{
b = a;
} else
{
b *= a;
}
++ f;
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
//除法模式
if ( d == 4 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
scanf ( "%lf" , & a );
if ( f == 1 )
{
if ( a == 0 ) //判断分母是否为0
{
printf ( "分母不能为0 \n" );
while ( getchar ( ) != '\n' );
c = 1; //循环标识
continue;
} else
{
b = a;
}
} else
{
b /= a;
}
//判断有没有进行错误输入循环
if ( a == 1 )
{
f = 1;
} else
{
++ f;
}
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int d , e , g; //需要计算的模式,需要计算的数量,判断循环几次,标记是否进行了循环
double a , b , c; //初始化的数字
int f = 1;
while ( 1 )
{
//获取用户需要计算的模式
printf ( " \n" );
printf ( "0.退出计算机 \n" );
printf ( "1.加法模式 \n" );
printf ( "2.减法模式 \n" );
printf ( "3.乘法模式 \n" );
printf ( "4.除法模式 \n" );
//获取用户输入的字符
printf ( "请输入对应的数字进入: " );
scanf ( "%d" , & d );
if ( d > 4 || d < 0 ) //判断数字是否符合条件
{
printf ( "请输入符合条件的数字 \n" );
while ( getchar ( ) != '\n' );
continue;
}
//输入0退出
if ( d == 0 )
{
exit ( 0 );
}
//获取用户需要计算的个数
printf ( "请输入需要的个数:" );
scanf ( "%d" , & e );
if ( e <= 0 ) //判断数字是否合法
{
printf ( "请输入合法的数字 \n" );
while ( getchar ( ) != '\n' );
continue;
}
//加法模式
if ( d == 1 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
++ f;
scanf ( "%lf" , & a );
b += a;
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
//减法模式
if ( d == 2 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
scanf ( "%lf" , & a );
if ( f == 1 )
{
b = a;
} else
{
b -= a;
}
++ f;
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
//乘法模式
if ( d == 3 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
scanf ( "%lf" , & a );
if ( f == 1 )
{
b = a;
} else
{
b *= a;
}
++ f;
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
//除法模式
if ( d == 4 )
{
for ( g = 1 ; g <= e ; g ++ )
{
printf ( "请输入第%d位数:" , f );
scanf ( "%lf" , & a );
if ( f == 1 )
{
if ( a == 0 ) //判断分母是否为0
{
printf ( "分母不能为0 \n" );
while ( getchar ( ) != '\n' );
c = 1; //循环标识
continue;
} else
{
b = a;
}
} else
{
b /= a;
}
//判断有没有进行错误输入循环
if ( a == 1 )
{
f = 1;
} else
{
++ f;
}
}
printf ( "结果为:%lf \n \n" , b );
while ( getchar ( ) != '\n' ); //读取字符到回车结束
}
}
return 0;
}

View File

@ -1,158 +1,158 @@
#include<stdio.h>
#include<stdlib.h>
int main ()
{
while ( 1 ) //计算器运行
{
//初始化
double result = 0; //结果
double array_1[100]; //储存数字的的数组
char array_2[100]; //储存符号
double array_3[100]; //储存乘除数字的的数组
char array_4[100]; //储存乘除符号
int tab_2 = 0 , tab_3 = 0 , tab_4 = 0 , tab_7 = 0 , tab_8 = 0 , tab_a = 0;//乘除里符号接收的第几位;用于判断接收位数;加减第几位;用获取乘除数字的次数;判断用户是否退出获取加减循环
int tab_1 = 0 , tab_5 = 0 , tab_6 = 0; //判断用户是否退出获取数字循环,判断用户是否退出获取乘除循环;
int tab_9; //主页面判断
//主页面
printf ( "---主页--- \n" );
printf ( "输入0退出 \n" );
printf ( "任意字符或双回车进入计算:" );
tab_9 = getchar ( );
if ( tab_9 == '0' )
{
printf ( "欢迎下次使用!" );
return 1;
}
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "-------- \n" );
//此层循环计算加减开始
for ( tab_4 = 0 ; tab_8 == 0 ; tab_4 ++ )
{
//此层循环计算乘除开始
for ( tab_7 = 0 ; tab_5 == 0 ; tab_7 ++ )
{
//此循环接收用户输入的数据开始
for ( ; tab_1 == 0 ; )
{
//获取用户输入的数字
printf ( "请输入第%d位数:" , tab_3 + 1 );
while ( scanf ( "%lf" , & array_1[ tab_3 ] ) != 1 )
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' ); //清楚缓存
continue; //重新开始循环
}
while ( getchar ( ) != '\n' ); //清楚缓存
//获取用户输入的符号
printf ( "+ or - or * or / or = \n" );
printf ( "请输入第%d位符号:" , tab_3 + 1 );
scanf ( " %c" , & array_2[ tab_3 ] );
while ( array_2[ tab_3 ] != '+' && array_2[ tab_3 ] != '-' && array_2[ tab_3 ] != '*' &&
array_2[ tab_3 ] != '/' && array_2[ tab_3 ] != '=' )
{
printf ( "请输入正确的符号:" );
while ( getchar ( ) != '\n' ); //清楚缓存
scanf ( " %c" , & array_2[ tab_3 ] ); //重新获取字符
}
while ( getchar ( ) != '\n' ); //清楚缓存
//分母不能为0
if ( tab_3 == 0 && array_1[ tab_3 ] == 0 && array_2[ tab_3 ] == '/' )
{
printf ( "分母不能为0,请重新输入 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
continue; //重新开始循环
}
//判断是=结束计算出结果
if ( array_2[ tab_3 ] == '=' )
{
tab_1 = 1;
break;
}
//次数的自增
++ tab_3;
}
//此循环接收用户输入的数据结束
//计算乘法
if ( array_2[ tab_7 ] == '*' )
{
array_1[ tab_7 + 1 ] = array_1[ tab_7 ] * array_1[ tab_7 + 1 ]; //计算
}
//计算除法
if ( array_2[ tab_7 ] == '/' )
{
array_1[ tab_7 + 1 ] = array_1[ tab_7 ] / array_1[ tab_7 + 1 ]; //计算
}
//跳过加法减法
if ( array_2[ tab_7 ] == '+' || array_2[ tab_7 ] == '-' )
{
array_3[ tab_2 ] = array_1[ tab_7 ]; //储存计算的数
array_4[ tab_2 ] = array_2[ tab_7 ]; //储存符号
++ tab_2; //增加符号存储位置
}
//退出乘除
if ( array_2[ tab_7 ] == '=' )
{
array_3[ tab_2 ] = array_1[ tab_7 ]; //储存计算的数
array_4[ tab_2 ] = array_2[ tab_7 ]; //储存符号
tab_5 = 1; //防止再次进入循环
break; //退出循环
}
}
//此层循环计算乘除结束
if ( tab_4 == 0 )
{
result = array_3[ tab_4 ];
} else
{
//加法
if ( array_4[ tab_a ] == '+' )
{
result += array_3[ tab_4 ];
}
//加法
if ( array_4[ tab_a ] == '-' )
{
result -= array_3[ tab_4 ];
}
//计算最终结果
if ( array_4[ tab_a ] == '=' )
{
printf ( "结果为%lf \n" , result );
tab_8 = 1;
printf ( "按任意按键返回主菜单 \n" );
getchar ( );
break;
}
//符号的自增
++ tab_a;
}
}
//此层循环计算加减结束
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main ()
{
while ( 1 ) //计算器运行
{
//初始化
double result = 0; //结果
double array_1[100]; //储存数字的的数组
char array_2[100]; //储存符号
double array_3[100]; //储存乘除数字的的数组
char array_4[100]; //储存乘除符号
int tab_2 = 0 , tab_3 = 0 , tab_4 = 0 , tab_7 = 0 , tab_8 = 0 , tab_a = 0;//乘除里符号接收的第几位;用于判断接收位数;加减第几位;用获取乘除数字的次数;判断用户是否退出获取加减循环
int tab_1 = 0 , tab_5 = 0 , tab_6 = 0; //判断用户是否退出获取数字循环,判断用户是否退出获取乘除循环;
int tab_9; //主页面判断
//主页面
printf ( "---主页--- \n" );
printf ( "输入0退出 \n" );
printf ( "任意字符或双回车进入计算:" );
tab_9 = getchar ( );
if ( tab_9 == '0' )
{
printf ( "欢迎下次使用!" );
return 1;
}
while ( getchar ( ) != '\n' ); //清楚缓存
printf ( "-------- \n" );
//此层循环计算加减开始
for ( tab_4 = 0 ; tab_8 == 0 ; tab_4 ++ )
{
//此层循环计算乘除开始
for ( tab_7 = 0 ; tab_5 == 0 ; tab_7 ++ )
{
//此循环接收用户输入的数据开始
for ( ; tab_1 == 0 ; )
{
//获取用户输入的数字
printf ( "请输入第%d位数:" , tab_3 + 1 );
while ( scanf ( "%lf" , & array_1[ tab_3 ] ) != 1 )
{
printf ( "请输入合法的数字:" );
while ( getchar ( ) != '\n' ); //清楚缓存
continue; //重新开始循环
}
while ( getchar ( ) != '\n' ); //清楚缓存
//获取用户输入的符号
printf ( "+ or - or * or / or = \n" );
printf ( "请输入第%d位符号:" , tab_3 + 1 );
scanf ( " %c" , & array_2[ tab_3 ] );
while ( array_2[ tab_3 ] != '+' && array_2[ tab_3 ] != '-' && array_2[ tab_3 ] != '*' &&
array_2[ tab_3 ] != '/' && array_2[ tab_3 ] != '=' )
{
printf ( "请输入正确的符号:" );
while ( getchar ( ) != '\n' ); //清楚缓存
scanf ( " %c" , & array_2[ tab_3 ] ); //重新获取字符
}
while ( getchar ( ) != '\n' ); //清楚缓存
//分母不能为0
if ( tab_3 == 0 && array_1[ tab_3 ] == 0 && array_2[ tab_3 ] == '/' )
{
printf ( "分母不能为0,请重新输入 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
continue; //重新开始循环
}
//判断是=结束计算出结果
if ( array_2[ tab_3 ] == '=' )
{
tab_1 = 1;
break;
}
//次数的自增
++ tab_3;
}
//此循环接收用户输入的数据结束
//计算乘法
if ( array_2[ tab_7 ] == '*' )
{
array_1[ tab_7 + 1 ] = array_1[ tab_7 ] * array_1[ tab_7 + 1 ]; //计算
}
//计算除法
if ( array_2[ tab_7 ] == '/' )
{
array_1[ tab_7 + 1 ] = array_1[ tab_7 ] / array_1[ tab_7 + 1 ]; //计算
}
//跳过加法减法
if ( array_2[ tab_7 ] == '+' || array_2[ tab_7 ] == '-' )
{
array_3[ tab_2 ] = array_1[ tab_7 ]; //储存计算的数
array_4[ tab_2 ] = array_2[ tab_7 ]; //储存符号
++ tab_2; //增加符号存储位置
}
//退出乘除
if ( array_2[ tab_7 ] == '=' )
{
array_3[ tab_2 ] = array_1[ tab_7 ]; //储存计算的数
array_4[ tab_2 ] = array_2[ tab_7 ]; //储存符号
tab_5 = 1; //防止再次进入循环
break; //退出循环
}
}
//此层循环计算乘除结束
if ( tab_4 == 0 )
{
result = array_3[ tab_4 ];
} else
{
//加法
if ( array_4[ tab_a ] == '+' )
{
result += array_3[ tab_4 ];
}
//加法
if ( array_4[ tab_a ] == '-' )
{
result -= array_3[ tab_4 ];
}
//计算最终结果
if ( array_4[ tab_a ] == '=' )
{
printf ( "结果为%lf \n" , result );
tab_8 = 1;
printf ( "按任意按键返回主菜单 \n" );
getchar ( );
break;
}
//符号的自增
++ tab_a;
}
}
//此层循环计算加减结束
}
return 0;
}

View File

@ -1,108 +1,108 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
void live(char symbol[],int length)
{
printf ("\n\n\n\n");
system ("color 0c");//改变颜色
int length_2=length/10;//中间部分长度
int length_1=length/3+1+length_2-1;//上半部分长度
int length_3=length-length_2-length_1+4+length_2-1;//下半部分长度
int length_a=length/5*2;//上半2/5前位置
int length_a_1=length/5*2+2;//上半2/5后位置
int length_b=length/5*4;//上半4/5前位置
int length_b_1=length/5*4+2;//上半4/5后位置
int size= strlen (symbol);//计算空格需要打多少
int length_e=1;//下半左面
int length_f=length/2*3-length_2-1;//下半右面
//打印上半
for ( int i = 1 ; i <= length_1 ; i++ )
{
for ( int j = 1 ; j <= length_a ; ++ j )
{
for ( int k = 1 ; k <= size ; k++ )
{
printf (" ");
}
}
for ( int j = length_a ; j <= length_a_1 ; j++ )
{
printf ("%s",symbol);
}
for ( int j = length_a_1 ; j <=length_b ; j++ )
{
for ( int k = 1 ; k <= size ; k++ )
{
printf (" ");
}
}
for ( int j = length_b ; j <= length_b_1 ; j++ )
{
printf ("%s",symbol);
}
if(length_a_1<length_b)
{
++length_a_1;
--length_b;
}
else if(length_a_1==length_b)
{
++length_a_1;
}
--length_a;
++length_b_1;
sleep(1);
printf ("\n");//输出回车
}
//打印中间
for ( int i = 1 ; i <=length_2 ; i++ )
{
for ( int j = 1 ; j <length/4*6; j++ )
{
printf ("%s",symbol);
}
sleep(1);
printf ("\n");
}
//打印下面
for ( int i = 1 ; i < length_3 ; i++ )
{
for ( int j = 1 ; j <= length_e ; j++ )
{
for ( int k = 1 ; k <= size ; k++ )
{
printf (" ");
}
}
for ( int j = length_e ; j <= length_f ; j++ )
{
printf ("%s",symbol);
}
sleep (1);
++length_e;
--length_f;
printf ("\n");
}
exit (0);
}
int main()
{
tab:
srand (time(NULL));
char symbol[99];
int length;
printf ("请输入需要打印的长度(8-20):");
scanf ("%d",&length);
if(length<8||length>20)
{
goto tab;
}
printf ("请输入需要填充的符号或者是单词:");
scanf ("%s",symbol);
live (symbol,length);
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
void live(char symbol[],int length)
{
printf ("\n\n\n\n");
system ("color 0c");//改变颜色
int length_2=length/10;//中间部分长度
int length_1=length/3+1+length_2-1;//上半部分长度
int length_3=length-length_2-length_1+4+length_2-1;//下半部分长度
int length_a=length/5*2;//上半2/5前位置
int length_a_1=length/5*2+2;//上半2/5后位置
int length_b=length/5*4;//上半4/5前位置
int length_b_1=length/5*4+2;//上半4/5后位置
int size= strlen (symbol);//计算空格需要打多少
int length_e=1;//下半左面
int length_f=length/2*3-length_2-1;//下半右面
//打印上半
for ( int i = 1 ; i <= length_1 ; i++ )
{
for ( int j = 1 ; j <= length_a ; ++ j )
{
for ( int k = 1 ; k <= size ; k++ )
{
printf (" ");
}
}
for ( int j = length_a ; j <= length_a_1 ; j++ )
{
printf ("%s",symbol);
}
for ( int j = length_a_1 ; j <=length_b ; j++ )
{
for ( int k = 1 ; k <= size ; k++ )
{
printf (" ");
}
}
for ( int j = length_b ; j <= length_b_1 ; j++ )
{
printf ("%s",symbol);
}
if(length_a_1<length_b)
{
++length_a_1;
--length_b;
}
else if(length_a_1==length_b)
{
++length_a_1;
}
--length_a;
++length_b_1;
sleep(1);
printf ("\n");//输出回车
}
//打印中间
for ( int i = 1 ; i <=length_2 ; i++ )
{
for ( int j = 1 ; j <length/4*6; j++ )
{
printf ("%s",symbol);
}
sleep(1);
printf ("\n");
}
//打印下面
for ( int i = 1 ; i < length_3 ; i++ )
{
for ( int j = 1 ; j <= length_e ; j++ )
{
for ( int k = 1 ; k <= size ; k++ )
{
printf (" ");
}
}
for ( int j = length_e ; j <= length_f ; j++ )
{
printf ("%s",symbol);
}
sleep (1);
++length_e;
--length_f;
printf ("\n");
}
exit (0);
}
int main()
{
tab:
srand (time(NULL));
char symbol[99];
int length;
printf ("请输入需要打印的长度(8-20):");
scanf ("%d",&length);
if(length<8||length>20)
{
goto tab;
}
printf ("请输入需要填充的符号或者是单词:");
scanf ("%s",symbol);
live (symbol,length);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,24 @@
#include<stdio.h>
int main ()
{
int figure_1 = 1;
int figure_2 = 1;
int result;
while ( figure_1 <= 9 )
{
for ( figure_2 = 1 ; figure_2 <= figure_1 ; figure_2 ++ )
{
result = figure_1 * figure_2;
printf ( "%d*%d=%d " , figure_1 , figure_2 , result );
if ( figure_1 == figure_2 )
{
printf ( "\n" );
++ figure_1;
break;
}
}
}
return 0;
#include<stdio.h>
int main ()
{
int figure_1 = 1;
int figure_2 = 1;
int result;
while ( figure_1 <= 9 )
{
for ( figure_2 = 1 ; figure_2 <= figure_1 ; figure_2 ++ )
{
result = figure_1 * figure_2;
printf ( "%d*%d=%d " , figure_1 , figure_2 , result );
if ( figure_1 == figure_2 )
{
printf ( "\n" );
++ figure_1;
break;
}
}
}
return 0;
}

View File

@ -1,32 +1,32 @@
#include <stdio.h>
void cfd(int a,int b,int c)
{
if(a<=b)
{
printf ("%d*%d=%d ",a,b,a*b);
++a;
cfd(a,b,c);
}
else if(b < c)
{
a=1;
printf ("\n");
++b;
cfd (a,b,c);
}
else if(b==c)
{
return;
}
}
int main()
{
int a ;
printf ("请输入:");
scanf ("%d",&a);
cfd (1,1,a);
#include <stdio.h>
void cfd(int a,int b,int c)
{
if(a<=b)
{
printf ("%d*%d=%d ",a,b,a*b);
++a;
cfd(a,b,c);
}
else if(b < c)
{
a=1;
printf ("\n");
++b;
cfd (a,b,c);
}
else if(b==c)
{
return;
}
}
int main()
{
int a ;
printf ("请输入:");
scanf ("%d",&a);
cfd (1,1,a);
}

View File

@ -1,70 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
//初始化
unsigned int time_down; //关机时间
int pick_home;//主页选择
char shutdown_commend[100];//初始化储存关机字符
printf ("0.取消关机 \n");
printf ("1.强制关机 \n");
printf ("2.立即注销 \n");
printf ("3.定时关机 \n");
printf ("4.定时重启 \n");
printf ("请输入你需要执行的操作:");
scanf ("%d",&pick_home);
switch ( pick_home )
{
case 0:
{
system ("shutdown -a");
break;
}
case 1:
{
system ("shutdown -p");
break;
}
case 2:
{
system ("shutdown -l");
break;
}
case 3:
{
pick_down:
printf ("请输入你需要多少分钟之后关机:");
while ( scanf ("%u",&time_down) != 1 || time_down < 0 )
{
printf ( "请输入合法的数字 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
goto pick_down; //重新开始
}
time_down = time_down * 60; //默认秒换分钟
sprintf (shutdown_commend,"shutdown -s -t %u",time_down);
system (shutdown_commend);
break;
}
case 4:
{
pick_reboot:
printf ("请输入你需要多少分钟之后重启:");
while ( scanf ("%u",&time_down) != 1 || time_down < 0 )
{
printf ( "请输入合法的数字 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
goto pick_reboot; //重新开始
}
time_down = time_down * 60; //默认秒换分钟
sprintf (shutdown_commend,"shutdown -r -t %u",time_down);
system (shutdown_commend);
break;
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
//初始化
unsigned int time_down; //关机时间
int pick_home;//主页选择
char shutdown_commend[100];//初始化储存关机字符
printf ("0.取消关机 \n");
printf ("1.强制关机 \n");
printf ("2.立即注销 \n");
printf ("3.定时关机 \n");
printf ("4.定时重启 \n");
printf ("请输入你需要执行的操作:");
scanf ("%d",&pick_home);
switch ( pick_home )
{
case 0:
{
system ("shutdown -a");
break;
}
case 1:
{
system ("shutdown -p");
break;
}
case 2:
{
system ("shutdown -l");
break;
}
case 3:
{
pick_down:
printf ("请输入你需要多少分钟之后关机:");
while ( scanf ("%u",&time_down) != 1 || time_down < 0 )
{
printf ( "请输入合法的数字 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
goto pick_down; //重新开始
}
time_down = time_down * 60; //默认秒换分钟
sprintf (shutdown_commend,"shutdown -s -t %u",time_down);
system (shutdown_commend);
break;
}
case 4:
{
pick_reboot:
printf ("请输入你需要多少分钟之后重启:");
while ( scanf ("%u",&time_down) != 1 || time_down < 0 )
{
printf ( "请输入合法的数字 \n" );
while ( getchar ( ) != '\n' ); //清楚缓存
goto pick_reboot; //重新开始
}
time_down = time_down * 60; //默认秒换分钟
sprintf (shutdown_commend,"shutdown -r -t %u",time_down);
system (shutdown_commend);
break;
}
}
return 0;
}

View File

@ -1,50 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
//生成随机数字
srand ( ( unsigned int ) time ( NULL ) ); //设置睡觉函数预定值
int figure_1 = rand ( ) % 100; //接收随机数
//初始化
int figure_2; //用户输入的数字
int number_times = 2; //用户输入的次数
printf ( "请输入%d开启原神\n" , figure_1 );
printf ( "请输入:" );
while ( scanf ( "%d" , & figure_2 ) )
{
if ( figure_1 == figure_2 )
{
printf ( "智力正常,原神启动\n" );
system ( "start https://genshin.hoyoverse.com" );
return 1;
}
if ( number_times == 0 )
{
printf ( "智力缺陷关闭电脑" );
system ( "shutdown -s" );
return 1;
}
if ( figure_1 < figure_2 )
{
printf ( "还剩%d次机会" , number_times );
printf ( "数字大了请重新输入:" );
while ( getchar ( ) != '\n' ); //清除缓存
-- number_times; //减少次数
continue;
}
if ( figure_1 > figure_2 )
{
printf ( "还剩%d次机会" , number_times );
printf ( "数字小了请重新输入:" );
while ( getchar ( ) != '\n' ); //清除缓存
-- number_times; //减少次数
continue;
}
}
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
//生成随机数字
srand ( ( unsigned int ) time ( NULL ) ); //设置睡觉函数预定值
int figure_1 = rand ( ) % 100; //接收随机数
//初始化
int figure_2; //用户输入的数字
int number_times = 2; //用户输入的次数
printf ( "请输入%d开启原神\n" , figure_1 );
printf ( "请输入:" );
while ( scanf ( "%d" , & figure_2 ) )
{
if ( figure_1 == figure_2 )
{
printf ( "智力正常,原神启动\n" );
system ( "start https://genshin.hoyoverse.com" );
return 1;
}
if ( number_times == 0 )
{
printf ( "智力缺陷关闭电脑" );
system ( "shutdown -s" );
return 1;
}
if ( figure_1 < figure_2 )
{
printf ( "还剩%d次机会" , number_times );
printf ( "数字大了请重新输入:" );
while ( getchar ( ) != '\n' ); //清除缓存
-- number_times; //减少次数
continue;
}
if ( figure_1 > figure_2 )
{
printf ( "还剩%d次机会" , number_times );
printf ( "数字小了请重新输入:" );
while ( getchar ( ) != '\n' ); //清除缓存
-- number_times; //减少次数
continue;
}
}
}