当前位置:网站首页>编程测试6.21
编程测试6.21
2022-07-30 05:46:00 【缘聚654】
一 设计一个猜数字游戏,即系统随机出一个0-100的整数,用户输入数字,提示输出大还是小,超过4次则为用户失败,游戏结束后询问用户是否下一轮。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void game()
{
int x,n,i=0;
n=rand()%100+1;
for(i=0;i<4;i++)
{
scanf("%d",&x);
if(x<n)
printf("小\n");
if(x>n)
printf("大\n");
if(x==n)
{
printf("正确\n");
break;
}
}
if(i>3)
{
printf("失败\n");
}
}
int main()
{
int m;
do
{
game();
printf("是否继续:(1:继续,0:结束)\n");
scanf("%d",&m);
} while(m!=0);
printf("游戏结束!");
}四
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
void fun1(int n)
{
if(n/2)
fun1(n/2);
putchar('0'+n%2);
}
void fun2(int n)
{
if(n/8)
fun2(n/8);
putchar('0'+n%8);
}
void fun3(int n)
{
if(n/16)
fun3(n/16);
int i = n%16;
if(i<10)
putchar('0'+i);
else
putchar('a'+i-10);
}
int fun4(char *str)
{
int num = 0;
while(*str != '\0')
{
int i = *str-'0';
if(i>=0 && i<=1)
num = num*2+i;
str++;
}
return num;
}
int fun5(char *str)
{
int num = 0;
while(*str != '\0')
{
int i = *str-'0';
if(i>=0 && i<8)
num = num*8+i;
str++;
}
return num;
}
int fun6(char *str)
{
int num = 0;
while(*str != '\0')
{
char ch = *str;
if(ch>='0' && ch<='9')
num = num*16+ch-'0';
if(ch>='a' && ch<='f')
num = num*16+10+ch-'a';
str++;
}
return num;
}
int main()
{
int i,j,num;
char ch,*s;
scanf("输入%d进制";&i);
if(i==2)
{
scanf("%s",ch);
*s=&ch;
num=fun4(*s);
}
if(i==8)
{
scanf("%s",ch);
*s=&ch;
num=fun5(*s);
}
if(i==16)
{
scanf("%s",ch);
*s=&ch;
num=fun6(*s);
}
scanf("输出%d",&j);
if(i==2)
{
scanf("%s",ch);
*s=&ch;
fun1(num);
} if(i==6)
{
scanf("%s",ch);
*s=&ch;
fun2(num);
} if(i==16)
{
scanf("%s",ch);
*s=&ch;
fun3(num);
}
if(i==10)
{
printf(%d,num);
}
}
五
#include<stdio.h>
int main()
{
int a[n][n] = { };
int b[n][n] = { };
int c[n][n] = { 0 };
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d %d",&a[i][j],&b[i][j])
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
c[i][j]=a[i][j]+b[i][j];
}
if(i==n-1&&j=0)
printf("%d",c[i][j]);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
c[i][j]=a[i][j]-b[i][j];
}
if(i==n-1&&j=0)
printf("%d",c[i][j]);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
c[i][j]=a[i][j]*b[i][j];
}
if(i==n-1&&j=0)
printf("%d",c[i][j]);
}
}边栏推荐
- "R Language + Remote Sensing" Comprehensive Evaluation Method of Water Environment
- 2020-09-03解决pip install安装非常慢[Errno 101] 网络不可达问题
- SSH-RSA密钥
- 服务器基础知识:包含基本概念,作用,服务器选择,服务器管理等(学习来自米拓建站)
- >>> /deep/ ::v-deep 深度作用选择器
- 【江科大自化协stm32F103c8t6】笔记之【入门32单片机及GPIO初始化参数配置】
- 如何开发出成功的硬件产品,一个产品由概念的产生到产品的落地量产又需要经历哪些流程呢?
- 《C陷阱和缺陷》void (*signal(int , void(*)(int)))(int)的深刻解读
- js 替换字符串中所有 “ 引号 —— 数据处理
- IEEE在指定期刊下搜索相关论文
猜你喜欢

二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通

vscode set sublime theme

QT serial 4: LORA test platform based on QT and STM32H750 (3)

ES6 syntax notes (ES6~ES11)

BLDC电机应用持续火爆,“网红神器”筋膜枪前景几何?

【部分项目展示】

TCP为什么要三次握手,握手过程中丢包会怎么样?

探究make_shared效率

Acwing刷题第一节
![[Punctuality Atom] Simple application of sys.c, sys.h bit-band operations](/img/7f/d9f480ab9a1e542e4fa1fda7978e4c.png)
[Punctuality Atom] Simple application of sys.c, sys.h bit-band operations
随机推荐
Simple use of xftp
This beta version of Typora is expired, please download and install a newer; workaround
CPU缓存一致性问题
[Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Entry 32 MCU and GPIO initialization parameter configuration]
This beta version of Typora is expired, please download and install a newer;解决方法
2020-09-03解决pip install安装非常慢[Errno 101] 网络不可达问题
The most complete difference between sizeof and strlen, as well as pointer and array operation analysis
>>> /deep/ ::v-deep 深度作用选择器
干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
sizeof和strlen最全区别,以及指针和数组运算解析
QT serial 2: LORA test platform based on QT and STM32H750 (1)
QT串口和CAN数据动态实时显示最后日志
"R Language + Remote Sensing" Comprehensive Evaluation Method of Water Environment
Vim查找字符
Deep Interpretation of void (*signal(int , void(*)(int)))(int) in "C Traps and Defects"
Acwing Brush Questions Section 1
TCP建立连接的过程
VsCode与Sublime编辑器优缺点对比
多层板的层数,为啥选项都是偶数?就不能选奇数?
Acwing刷题第一节