一个简单的数学题

一个简单的数学题

时间限制: 3000 ms  |  内存限制: 65535 KB
难度: 3
描述
zyc最近迷上了数学,一天,dj想出了一道数学题来难住他。算出1/n,但zyc一时答不上来希望大家能编程帮助他。
输入
第一行整数T,表示测试组数。后面T行,每行一个整数 n (1<=|n|<=10^5).
输出
输出1/n. (是循环小数的,只输出第一个循环节).
样例输入
4
2
3
7
168
样例输出
0.5
0.3
0.142857

0.005952380

//模拟手工计算, 并标记余数, 遇到重复余数就是出现循环节

#include <stdio.h>
#include <string.h>

int mark[100001];

int main()
{
    int n, temp, res;
    scanf("%d", &n);
    while(n--)
    {
        memset(mark, 0, sizeof(mark));
        scanf("%d", &temp);
        if(temp == 1)
        {
            printf("1\n");
        }
        else
        {
            printf("0.");
            res = 1;
            while(res != 0 && !mark[res])
            {
                mark[res] = 1;         //标记
                printf("%d", res*10/temp);
                res = (res*10)%temp;
            }
            printf("\n");
        }
    }
    return 0;
}


在JavaScript中为小学生设计数学题目,我们通常会关注基础算术运算,比如加减乘除以及简单应用题。这里有一个简单的例子,我们将创建一个函数来生成加法和减法的题目,并让用户输入答案进行验证: ```javascript function generateQuestion(level="easy") { // 题目类型,level可以是"easy"、"medium"或"hard" const operators = ["+", "-"]; let firstNumber, secondNumber; if (level === "easy") { // 简单水平 firstNumber = Math.floor(Math.random() * 20) + 1; // 1-20的数字 secondNumber = Math.floor(Math.random() * 10) + 1; // 1-10的数字 } else if (level === "medium") { // 中等水平 firstNumber = Math.floor(Math.random() * 50) + 1; secondNumber = Math.floor(Math.random() * 30) + 1; } else { // 困难水平 firstNumber = Math.floor(Math.random() * 100) + 1; secondNumber = Math.floor(Math.random() * 70) + 1; } const operation = operators[Math.floor(Math.random() * 2)]; // 随机选择一个运算符 let problem = `${firstNumber} ${operation} ${secondNumber}`; // 用户答题 return { question: prompt(`请解决这个问题:${problem}`), answer: parseInt(prompt("请输入你的答案:")), correctAnswer: firstNumber + (operation === "+" ? secondNumber : -secondNumber) }; } // 使用示例 const quiz = generateQuestion(); console.log(quiz.question); const userAnswer = quiz.answer; // 检查答案是否正确 if (userAnswer === quiz.correctAnswer) { console.log("恭喜,答对了!"); } else { console.log(`很遗憾,错误的答案。正确答案是 ${quiz.correctAnswer}`); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值