#include <string.h>
#include <stdlib.h>
#include <time.h>
#define L 100 //定义最大字符长度为 100
int main()
{
srand(unsigned(time(NULL)))
char str[L] = {}, teststr[L] = {}
int length, RightCount = 0
float Precision
length = rand() % L + 1 //生成随机的字符串长度
for (int i = 0 i < length i++)
{
str[i] = rand() % 26 + 'a' //默认字符为小写字符
putchar(str[i])
}
printf("\nPlease input the above string :\n")
gets(teststr) //保存输入的字符串
for (int i = 0 i < length i++)//计算准确的字符个数
{
if (teststr[i] == str[i]) RightCount++
}
Precision = RightCount * 1.0 / length//计算准确率
printf("Precision : %.2f%\n", Precision * 100) //准确率保留两位小数输出
return 0
}
测试样例:
jvgvmsnpfia
Please input the above string :
jlkjlsnfdas
Precision : 27.27
#include<stdio.h>#include<stdlib.h>
#include <windows.h>
#include<time.h>
#include<math.h>
#define N 99
void sign(char n)
{
int a,b,c
srand( (unsigned)time( NULL ) )
a=1+(int)(10*rand()/(RAND_MAX+1.0)) //随机数产生
b=1+(int)(10*rand()/(RAND_MAX+1.0))
printf("%d%c%d=",a,n,b)
scanf("%d",&c)
if(n=='+')
{
if(c==a+b) printf("答对了!\n")
else printf("答案是%d\n",a+b)
}
if(n=='-')
{
if(c==a-b) printf("答对了!\n")
else printf("答案是%d\n",a-b)
}
if(n=='*')
{
if(c==a*b) printf("答对了!\n")
else printf("答案是%d\n",a*b)
}
if(n=='/')
{
if(c==a/b) printf("答对了!\n")
else {printf("答案是%d\n",a/b)}
}
}
void menu()
{
printf("1.加法运算\n")
printf("2.减法运算\n")
printf("3.乘法运算\n")
printf("4.除法运算\n")
printf("0.退出程序\n")
}
void main()
{
int num,i
for(i=0i++)
{
while(1){
menu()
printf("\n请选择功能:")
scanf("%d",&num)
switch(num)
{
case 4:sign('/')break
case 3:sign('*')break
case 2:sign('-')break
case 1:sign('+')break
case 0:return
}
printf("按任意键返回菜单\n")
getch()
system("cls") //清屏
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)