- 博客(17)
- 收藏
- 关注
原创 C语言练习题~扫雷小游戏1.0
扫雷小游戏实现功能:打印扫雷界面随机放置地雷,数量有后台自己设定玩家输入游戏坐标,以此判断输入的位置是否有雷如果有雷,游戏结束如果该位置没有雷,则统计该位置周围一圈有没有雷,有几个雷,并打印出来当玩家把所有位置上的雷排查完毕,玩家赢在此过程中,若踩雷,游戏结束未实现的功能:扫雷时,周围没有雷的情况下该位置不会展开下面是具体实现代码:主函数:#include "game.h"void menu(){ printf("***********************
2020-12-21 22:26:12 505 1
原创 C语言练习题~三子棋小游戏
三子棋小游戏游戏描述:如图,建立一个3*3的数组," * “代表玩家下棋,” # "代表电脑下棋当横三行或竖三行或斜对角线率先出现三个相同的字符,判断电脑或者玩家赢当棋盘满且不满足条件1的就是平局当棋盘不满且不满足1的就继续下棋整个游戏分为三个文件,分别是主函数源文件,游戏源文件和头文件。主函数源文件:#include "game.h"void menu(){ printf("*****************************\n"); printf("**
2020-12-20 09:57:11 220 1
原创 C语言练习题~冒泡排序
题目:对一维数组进行冒泡排序#include <stdio.h>int bubble_sort(int arr[],int sz){ int i = 0; for(i=0;i<sz;i++) { int j =0; for(j=0;j<sz-i;j++) { if (arr[j]>arr[j+1]) { int tmp
2020-12-18 16:51:28 700 1
原创 C语言练习题~分别用递归和迭代求n!
递归迭代#include <stdio.h>//1.递归int Facl(int n){ int i = 0; int ret = 1; for(i=1;i<=n;i++) { ret = ret*i; } return ret;}//2.迭代int Facl(int n){ if (n<2) return 1; else return n*Facl(.
2020-12-17 22:49:31 496
原创 C语言练习题~斐波那契数列
题目:求斐波那契数列。分别用1 递归2 循环求出斐波那契数列。#include <stdio.h>//1.递归int Fib(int n){ if (n<3) return 1; else return Fib(n-1)+Fib(n-2);}//2.循环int Fib(int n){ int a = 1; int b = 1; int c = 1; while(n>2)
2020-12-17 22:41:23 3851
原创 C语言练习题~关机程序
题目:输入特定字符取消关机。#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char input[20]={0}; system("shutdown -s -t 60"); again: printf("你的电脑将在一分钟内关机,请输入:马老师发生什么事了,就取消关机\n"); scanf("%s",input); if(st
2020-12-16 17:39:12 91
原创 C语言练习题~猜数字游戏
题目:猜数字游戏1.电脑会生成一个随机数2.猜数字#include <stdio.h>#include <stdlib.h>#include <time.h>void menu(){ printf("######################################\n"); printf("###### 1.play 0.exit ########\n"); printf("##############
2020-12-16 12:25:26 277
原创 C语言练习题~在有序数组中求输入元素的下标
#include <stdio.h>#include <string.h>int main() { char arr[]={1,2,3,4,5,6,7,8,9,10}; int k = 0; int sz = strlen(arr); int left = 0; int right = sz-1; scanf("%d",&k); while(left&
2020-12-15 22:18:20 201
原创 C语言练习题~求1!+2!+3!+...+n!的值
#include <stdio.h>int main() { int i = 0; int n = 0; int ret = 1; int sum = 0; for(n=1;n<=10;n++) { ret = 1; for(i=1;i<=n;i++) { ret = ret
2020-12-15 22:04:45 3733 1
原创 C语言练习题~求闰年
#include <stdio.h>int main() { int year = 0; int count = 0; for(year=1000;year<=2000;year++) { if (year%4==0 && year%100!=0) { printf("%d ",year);
2020-12-15 21:05:40 236
原创 C语言练习题~求最大公约数
题目:求最大公约数#include <stdio.h>int main() { int m = 0; int n = 0; int r = 0; scanf("%d %d",&m,&n); while(r=m%n) { m = n; n = r; } printf("%d\n",n);
2020-12-15 20:59:48 435
原创 C语言练习题~n的阶乘
题目:求n的阶乘。#include <stdio.h>int main() { int i = 0; int n = 0; int sum = 1; scanf("%d",&n); for(i=1;i<=n;i++) { sum = sum*i; } printf("n! = %d\n",sum); r
2020-12-15 20:54:25 282
原创 C语言练习题~多个字符向中间汇聚
题目:多个字符向中间汇聚#include <stdio.h>#include <string.h>int main() { char arr[]= "welcome to china!!!!!!!!"; char arr1[]="########################"; int left = 0; int right = strlen(arr)-1; int i = 0;
2020-12-15 20:45:53 74
原创 C语言练习题~乘法口诀表
题目:输出乘法口诀表。#include <stdio.h>int main() { int i = 0; int j = 1; for(i=1;i<=9;i++) { for(j=1;j<=i;j++) { printf("%d*%d=%2d ",i,j,i*j); // 2d 输出两位数字,不够两位的第一位用空格代替
2020-12-15 19:18:44 127
原创 C语言练习题~求10个数最大值
题目:求10个数最大值#include <stdio.h>int main() { int arr[] = {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10}; int max = arr[0]; //此处若max默认为0,则当数组元素全为负时,0为最大。 int i = 0; //得不到真值。 int sz = sizeof(arr)/ sizeof(arr[0]); for (
2020-12-15 08:50:32 324
原创 C语言练习题~分数求和
题目:分数求和计算 1/1-1/2+1/3…+1/99-1/100 的值。#include <stdio.h>int main() { double i = 0; double sum = 0; int flag = 1; //设置一个变量flag,用来控制每次加还是减。 for(i=1;i<=100;i++) { sum +=flag*1
2020-12-15 08:09:37 4490
原创 C语言练习题~求素数的个数
题目:求100~200内的素数,并求素数的个数。思路:判断一个数是素数,只需把i被2~i-1除,如果都不能整除,i就是素数。另外判断方法还可以简化,把i被2~i的平方根除,如果都不能整除,i就是素数。原因:假设i = a*b,有16 = 2 * 8 = 4 * 4,必有一个因数小于等于平方根i。#include <stdio.h>#include "math.h"int main() { int i; int j=0; int
2020-12-14 19:12:51 9974
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人