补一下前几天练习的代码
#include<stdio.h>
int main()
{
int n = 0;
//scanf("%d", &n);
int sum = 0;
for (int j = 1; j <= 10; j++)
{
int mul = 1;//mul应该放在里面才行,每一次新的阶乘mul都是1
for (int i = 1; i <= j; i++)
{
mul = mul * i;
}
sum = sum + mul;
}
printf("%d\n", sum);
return 0;
}
#include<stdio.h>
#include<string.h>
#include<windows.h>
int main()
{
char arr1[] = { "welcome to bit!!!!!!!!" };
char arr2[] = { "######################" };
int left = 0;
int right = strlen(arr1) - 1;
while (left <= right)
{
arr2[right] = arr1[right];
arr2[left] = arr1[left];
printf("%s\n", arr2);
Sleep(50);
left++;
right--;
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char password[20] = { 0 };
int i = 0;
for (i = 0; i < 3; i++)
{
printf("请输入密码:\n");
scanf("%s", password);
if (strcmp("123456", password) == 0)
{
printf("登录成功");
break;
}
else
{
printf("密码错误\n");
}
}
if (i == 3)
{
printf("登录失败\n");
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
void menu()
{
printf("************************\n");
printf("******* 1.play ******\n");
printf("******* 0.exit ******\n");
printf("************************\n");
//故意把exit设计成0的,这样while可以直接退出
}
void game()
{
//设置随机数
//srand(time(NULL));不用放在里面,因为放在里面每玩一次游戏,
//都会重新设计一个随机值,且速度快的话,两个随机数相差不大,甚至相等
int a = rand() % 100 + 1;
//printf("%d\n", a);
printf("请输入一个数字:\n");
int guess = 0;
scanf("%d", &guess);
if (guess > a)
{
printf("猜大了\n");
}
else if (guess < a)
{
printf("猜小了\n");
}
else
{
printf("恭喜你,猜对了\n");
}
}
int main()
{
srand(time(NULL));
int input = 0;
do
{
menu();
printf("请选择:\n");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("输入错误,请重新选择\n");
break;
}
} while (input);
return 0;
}
标签:guess,main,语言,int,break,8.18,printf,include
From: https://blog.csdn.net/fhgfyrsg/article/details/141292547