|
huajinghua
初级用户
 
积分 54
发帖 19
注册 2008-2-24
状态 离线
|
 『楼 主』:
出题目,全是我从C语言的题目中挑出来的
使用 LLM 解释/回答一下
本人从《C语言资料大全》中搜的题目,给新手学习,给高手练习。呵呵。本人也没时间做,留给大家做咯。
=================================================================
----------QQ:327828994
【程序1】
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去
掉不满足条件的排列。
【程序4】
题目:输入某年某月某日,判断这一天是这一年的第几天?
1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊
情况,闰年且输入月份大于3时需考虑多加一天。
【程序8】
题目:输出9*9口诀。
1.程序分析:分行与列考虑,共9行9列,i控制行,j控制列。
【程序9】
题目:要求输出国际象棋棋盘。
1.程序分析:用i控制行,j来控制列,根据i+j的和的变化来控制输出黑方格,还是白方格。
【程序11】
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月
后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21....
【程序12】
题目:判断101-200之间有多少个素数,并输出所有素数。
1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,
则表明此数不是素数,反之是素数。
【程序13】
题目:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数
本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。
1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。
【程序14】
题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成:
(1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。
(2)如果n<>k,但n能被k整除,则应打印出k的值,并用n除以k的商,作为新的正整数你n,
重复执行第一步。
(3)如果n不能被k整除,则用k+1作为k的值,重复执行第一步。
【程序16】
题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
1.程序分析:利用辗除法。
::作者提示:资料中未说明何为辗除法。根据C源码可知,辗除法(若a>b,让数a对数b求模得到c,再让数b对数c求模,得到d,再让c对d求模,一直循环直到最后的求模余数n=0)
【程序19】
题目:一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如6=1+2+3.编程
找出1000以内的所有完数。
【程序20】
题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在
第10次落地时,共经过多少米?第10次反弹多高?
【程序21】
题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个
第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下
的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
1.程序分析:采取逆向思维的方法,从后往前推断。
【程序23】
题目:打印出如下图案(菱形)
*
***
******
********
******
***
*
1.程序分析:先把图形分成两部分来看待,前四行一个规律,后三行一个规律,利用双重
for循环,第一层控制行,第二层控制列。
【程序24】
题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
1.程序分析:请抓住分子与分母的变化规律。
【程序25】
题目:求1+2!+3!+...+20!的和
1.程序分析:此程序只是把累加变成了累乘。
【程序28】
题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第
3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后
问第一个人,他说是10岁。请问第五个人多大?
1.程序分析:利用递归的方法,递归分为回推和递推两个阶段。要想知道第五个人岁数,需知道
第四人的岁数,依次类推,推到第一人(10岁),再往回推。
【程序30】
题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
【程序37】
题目:对10个数进行排序
1.程序分析:可以利用选择法,即从后9个比较过程中,选择一个最小的与第一个元素交换,
下次类推,即用第二个元素与后8个进行比较,并进行交换。
【程序61】
题目:打印出杨辉三角形(要求打印出10行如下图)
1.程序分析:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
【程序69】
题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出
圈子,问最后留下的是原来第几号的那位。
【程序80】
题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只
猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了
一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,
问海滩上原来最少有多少个桃子?
【程序81】
题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。
【程序83】
题目:求0—7所能组成的奇数个数。
【程序84】
题目:一个偶数总能表示为两个素数之和。
 
I, from the "C Language Data Compilation," the questions are for novice learning and expert practice. Hehe. I also don't have time to do it, leaving it for everyone to do.
=================================================================
----------QQ:327828994
【Program 1】
Title: There are 4 numbers 1, 2, 3, 4. How many three-digit numbers with distinct and non-repeating digits can be formed? And what are they?
1. Program analysis: The digits that can be filled in the hundreds, tens, and units places are all 1, 2, 3, 4. Form all permutations and then remove the ones that don't meet the conditions.
【Program 4】
Title: Input a certain year, month, and day, and judge which day of the year it is?
1. Program analysis: Take March 5th as an example. You should first add up the first two months, then add 5 days to get the day of the year. In special cases, if it's a leap year and the input month is greater than 3, an additional day needs to be considered.
【Program 8】
Title: Output the 9*9 multiplication table.
1. Program analysis: Consider by rows and columns. There are 9 rows and 9 columns. i controls the row and j controls the column.
【Program 9】
Title: Require to output a chessboard.
1. Program analysis: Use i to control the row and j to control the column. According to the change of the sum of i + j, control whether to output a black square or a white square.
【Program 11】
Title: Classical problem: There is a pair of rabbits. Starting from the 3rd month after birth, it gives birth to a pair of rabbits every month. After the little rabbits grow to the 3rd month, they give birth to a pair of rabbits every month. If the rabbits don't die, ask what is the total number of rabbits each month?
1. Program analysis: The law of rabbits is the sequence 1, 1, 2, 3, 5, 8, 13, 21....
【Program 12】
Title: Judge how many prime numbers are between 101 and 200, and output all prime numbers.
1. Program analysis: The method to judge a prime number: Use a number to divide by 2 to sqrt(this number) respectively. If it can be divided evenly, it means this number is not a prime number, otherwise it is a prime number.
【Program 13】
Title: Print out all "Narcissistic numbers". The so-called "Narcissistic number" refers to a three-digit number whose sum of the cubes of its digits is equal to the number itself. For example: 153 is a "Narcissistic number" because 153 = 1³ + 5³ + 3³.
1. Program analysis: Use a for loop to control numbers from 100 to 999. Decompose each number into the units digit, tens digit, and hundreds digit.
【Program 14】
Title: Decompose a positive integer into prime factors. For example: input 90, print out 90 = 2*3*3*5.
Program analysis: Decompose n into prime factors. First find the smallest prime number k, then complete the following steps:
(1) If this prime number is exactly equal to n, it means the process of decomposing prime factors has ended, and just print it out.
(2) If n<>k, but n can be divided evenly by k, then print out the value of k, and use the quotient of n divided by k as the new positive integer n, and repeat step 1.
(3) If n cannot be divided evenly by k, then use k+1 as the value of k, and repeat step 1.
【Program 16】
Title: Input two positive integers m and n, and find their greatest common divisor and least common multiple.
1. Program analysis: Use the Euclidean algorithm.
: : Author's prompt: The data does not explain what the Euclidean algorithm is. According to the C source code, the Euclidean algorithm (if a>b, let number a take the modulus of number b to get c, then let number b take the modulus of number c to get d, then let c take the modulus of d, and keep looping until the final modulus remainder n=0)
【Program 19】
Title: A number is called a "perfect number" if it is exactly equal to the sum of its factors. For example, 6 = 1 + 2 + 3. Program to find all perfect numbers within 1000.
【Program 20】
Title: A ball is freely dropped from a height of 100 meters. Each time it lands, it rebounds to half of the original height; then falls again. Find out how many meters it has passed in total when it lands for the 10th time? How high does it rebound for the 10th time?
【Program 21】
Title: Monkey peach-eating problem: The monkey picked several peaches on the first day, ate half of them immediately, and was not addicted, so ate one more. The next morning, it ate half of the remaining peaches again, and ate one more. In the following mornings, it ate half of the remaining peaches from the previous day plus one. On the morning of the 10th day, when it wanted to eat again, it saw that there was only one peach left. Find out how many peaches were picked on the first day.
1. Program analysis: Adopt the reverse thinking method and infer from the back to the front.
【Program 23】
Title: Print out the following pattern (diamond)
*
***
******
********
******
***
*
1. Program analysis: First treat the figure as two parts. The first four rows follow one pattern, and the last three rows follow another pattern. Use a double for loop. The first layer controls the row and the second layer controls the column.
【Program 24】
Title: There is a fraction sequence: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13... Find the sum of the first 20 terms of this sequence.
1. Program analysis: Please grasp the changing law of the numerator and the denominator.
【Program 25】
Title: Find the sum of 1 + 2! + 3! +... + 20!
1. Program analysis: This program just changes accumulation to cumulative multiplication.
【Program 28】
Title: There are 5 people sitting together. Ask how old the fifth person is? He said he is 2 years older than the fourth person. Ask how old the fourth person is, he said he is 2 years older than the third person. Ask the third person, he said he is 2 years older than the second person. Ask the second person, he said he is 2 years older than the first person. Finally ask the first person, he said he is 10 years old. Ask how old the fifth person is?
1. Program analysis: Use the recursive method. Recursion is divided into the backtracking and recursion stages. To know the age of the fifth person, need to know the age of the fourth person, and so on, push back to the first person (10 years old), then backtrack.
【Program 30】
Title: A 5-digit number, judge whether it is a palindrome number. That is, 12321 is a palindrome number, the units digit is the same as the ten-thousands digit, and the tens digit is the same as the thousands digit.
【Program 37】
Title: Sort 10 numbers
1. Program analysis: You can use the selection method. That is, in the comparison process of the last 9, select the smallest one to exchange with the first element, and so on, that is, use the second element to compare with the last 8 and exchange.
【Program 61】
Title: Print out Pascal's triangle (要求 print out 10 rows as shown below)
1. Program analysis:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
【Program 69】
Title: There are n people standing in a circle, numbered in order. Starting from the first person to report numbers (report numbers from 1 to 3), those who report 3 exit the circle. Ask who is the original number of the last remaining one.
【Program 80】
Title: There is a pile of peaches on the beach, and five monkeys come to divide them. The first monkey divides this pile of peaches into five equal parts, there is one more, this monkey throws the extra one into the sea and takes one part. The second monkey divides the remaining peaches into five equal parts again, there is one more, it also throws the extra one into the sea and takes one part. The third, fourth, and fifth monkeys all do this. Ask what is the minimum number of peaches originally on the beach?
【Program 81】
Title: 809*??=800*??+9*??+1 where?? represents a two-digit number, the result of 8*?? is a two-digit number, and the result of 9*?? is a three-digit number. Find the two-digit number represented by??, and the result after 809*??.
【Program 83】
Title: Find the number of odd numbers that can be composed of 0 - 7.
【Program 84】
Title: An even number can always be expressed as the sum of two prime numbers.
:P:P
|
|
2008-4-10 19:35 |
|
|
abcd
银牌会员
    
积分 1436
发帖 739
注册 2007-10-11
状态 离线
|
|
2008-4-10 19:58 |
|
|
huajinghua
初级用户
 
积分 54
发帖 19
注册 2008-2-24
状态 离线
|
|
2008-4-10 20:02 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 4 楼』:
第一题(程序1):
使用 LLM 解释/回答一下
@echo off
for /l %%i in (1,1,4) do set a=%%i&call :lp %%a%%
pause&goto :eof
:lp
for /l %%j in (1,1,4) do if not %%j equ %a% set b=%%j&call :loop %%a%% %%b%%
goto :eof
:loop
for /l %%k in (1,1,4) do (
if not %%k equ %a% set d=%%k
setlocal enabledelayedexpansion
if not !d! equ %b% set c=!d!
)
echo %a%%b%%c%
endlocal
goto :eof
Last edited by zw19750516 on 2008-4-11 at 04:02 PM ]
```@echo off
for /l %%i in (1,1,4) do set a=%%i&call :lp %%a%%
pause&goto :eof
:lp
for /l %%j in (1,1,4) do if not %%j equ %a% set b=%%j&call :loop %%a%% %%b%%
goto :eof
:loop
for /l %%k in (1,1,4) do (
if not %%k equ %a% set d=%%k
setlocal enabledelayedexpansion
if not !d! equ %b% set c=!d!
)
echo %a%%b%%c%
endlocal
goto :eof
```
Last edited by zw19750516 on 2008-4-11 at 04:02 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-10 20:15 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 5 楼』:
第三题(程序8):
使用 LLM 解释/回答一下
@echo off
for /l %%i in (1,1,9) do (
setlocal enabledelayedexpansion
for /l %%j in (1,1,%%i) do (
set a=%%i&set b=%%j
set /a c=!a!*!b!&set /a m+=1
if !c! lss 10 set c= !c!
set "var=!a!*!b!=!c!"
set str=!str! !var!
if !m! equ !a! echo !str!&set m=0&set str=
)
endlocal
)
pause>nul
Last edited by zw19750516 on 2008-4-11 at 04:03 PM ]
```batch
@echo off
for /l %%i in (1,1,9) do (
setlocal enabledelayedexpansion
for /l %%j in (1,1,%%i) do (
set a=%%i&set b=%%j
set /a c=!a!*!b!&set /a m+=1
if !c! lss 10 set c= !c!
set "var=!a!*!b!=!c!"
set str=!str! !var!
if !m! equ !a! echo !str!&set m=0&set str=
)
endlocal
)
pause>nul
```
Last edited by zw19750516 on 2008-4-11 at 04:03 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-10 20:25 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 6 楼』:
第二题(程序4):
使用 LLM 解释/回答一下
@echo off
:begin
cls
set /p var=输入要计算的日期(格式为2000-01-01):
if "%var:~4,1%%var:~7,1%"=="--" goto year
cls
echo 输入格式不正确!请返回正确输入。&ping /n 2 127.1>nul&goto begin
:year
set year=%var:~,4%
set /a str=%year%-%year%/4*4
:month
if %var:~5,1% equ 0 (set month=%var:~6,1%) else (set month=%var:~5,2%)
set /a month=%month%-1
if %month% equ 0 set /a number=0
if %month% equ 1 set /a number=31
if %month% equ 2 set /a number=31+28
if %month% equ 3 set /a number=31*2+28
if %month% equ 4 set /a number=31*2+30+28
if %month% equ 5 set /a number=31*3+30+28
if %month% equ 6 set /a number=31*3+30*2+28
if %month% equ 7 set /a number=31*4+30*2+28
if %month% equ 8 set /a number=31*5+30*2+28
if %month% equ 9 set /a number=31*5+30*3+28
if %month% equ 10 set /a number=31*6+30*3+28
if %month% equ 11 set /a number=31*6+30*4+28
if %str% equ 0 if %month% gtr 2 set /a number=%number%+1
:day
if %var:~8,1% equ 0 (set /a number=%number%+%var:~9,1%) else (set /a number=%
number%+%var:~8,2%)
cls
echo %var%是%year%年的第%number%天
pause>nul
Last edited by zw19750516 on 2008-4-11 at 04:03 PM ]
```
@echo off
:begin
cls
set /p var=Enter the date to calculate (format: 2000-01-01):
if "%var:~4,1%%var:~7,1%"=="--" goto year
cls
echo Incorrect input format! Please return to correct input.&ping /n 2 127.1>nul&goto begin
:year
set year=%var:~,4%
set /a str=%year%-%year%/4*4
:month
if %var:~5,1% equ 0 (set month=%var:~6,1%) else (set month=%var:~5,2%)
set /a month=%month%-1
if %month% equ 0 set /a number=0
if %month% equ 1 set /a number=31
if %month% equ 2 set /a number=31+28
if %month% equ 3 set /a number=31*2+28
if %month% equ 4 set /a number=31*2+30+28
if %month% equ 5 set /a number=31*3+30+28
if %month% equ 6 set /a number=31*3+30*2+28
if %month% equ 7 set /a number=31*4+30*2+28
if %month% equ 8 set /a number=31*5+30*2+28
if %month% equ 9 set /a number=31*5+30*3+28
if %month% equ 10 set /a number=31*6+30*3+28
if %month% equ 11 set /a number=31*6+30*4+28
if %str% equ 0 if %month% gtr 2 set /a number=%number%+1
:day
if %var:~8,1% equ 0 (set /a number=%number%+%var:~9,1%) else (set /a number=%
number%+%var:~8,2%)
cls
echo %var% is the %number%th day of %year%
pause>nul
```
Last edited by zw19750516 on 2008-4-11 at 04:03 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-10 20:45 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2008-4-10 20:49 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
判断天数
@echo off
set/p p1=输入年:
set/p p2=输入月:
set/p p3=输入日:
set/a pn="!(p1%%4) & !(!(p1%%100)) | !(p1%%400)"
for /f "tokens=%p2%" %%i in ("0 31 59 90 120 151 181 212 243 273 304 334") do set/a n=%%i+p3
if %P2% gtr 2 set/a n+=pn
if %P2% equ 2 if %P3% equ 29 if %pn% equ 0 echo %p1%年不是闰年 所以%P2%月不会有%P3%日&pause&exit
echo %p1%年%p2%月%p3%日 是 %p1% 年的第 %n% 天
pause
数字排列
@echo off&setlocal enabledelayedexpansion
set str=1 2 3 4
for %%a in (!str!) do (
set str1=!str:%%a=!
for %%b in (!str1!) do (
set str2=!str1:%%b=!
for %%c in (!str2!) do (
set str3=!str2:%%c=!
echo %%b%%c!str3: =!
set /a n+=1
)
)
)
echo 有%n%种排列
pause
求两位数
@echo off&setlocal enabledelayedexpansion
for /l %%i in (99,-1,10) do (
set/a m=%%i*8,n=%%i*9
if !m! lss 100 if !n! gtr 100 set/a mn=809*%%i&set str=%%i
)
echo 809 × %str% = %mn%
pause
第一天摘了多少桃
@echo off
set m=1
set n=10
:lp
set/a m+=1
set/a m=%m%*2,n-=1
if %n% gtr 1 goto lp
echo 第一天摘了 %m%
pause
排序数字
@echo off
set/p var=请输入数字
set var=%var: =%
:lp
set .%var:~0,1% %random%=a
set var=%var:~1%
if not "%var%" == "" goto :lp
set/p =排序后为:<nul
for /f "delims=.= " %%i in ('set .') do set/p =%%i<nul
echo.
pause
递加数
这个是我理解错了吧 改下
@echo off
for /l %%i in (1,1,20) do set/a n+=%%i
echo %n%
pause
Last edited by terse on 2008-4-11 at 09:32 AM ]
### Determine the Number of Days
```
@echo off
set/p p1=Enter the year:
set/p p2=Enter the month:
set/p p3=Enter the day:
set/a pn="!(p1%%4) & !(!(p1%%100)) | !(p1%%400)"
for /f "tokens=%p2%" %%i in ("0 31 59 90 120 151 181 212 243 273 304 334") do set/a n=%%i+p3
if %P2% gtr 2 set/a n+=pn
if %P2% equ 2 if %P3% equ 29 if %pn% equ 0 echo %p1% is not a leap year, so there is no %P3% day in %P2% month&pause&exit
echo %p1% year %p2% month %p3% day is the %n%th day of %p1% year
pause
```
### Number Permutations
```
@echo off&setlocal enabledelayedexpansion
set str=1 2 3 4
for %%a in (!str!) do (
set str1=!str:%%a=!
for %%b in (!str1!) do (
set str2=!str1:%%b=!
for %%c in (!str2!) do (
set str3=!str2:%%c=!
echo %%b%%c!str3: =!
set /a n+=1
)
)
)
echo There are %n% permutations
pause
```
### Find Two-Digit Number
```
@echo off&setlocal enabledelayedexpansion
for /l %%i in (99,-1,10) do (
set/a m=%%i*8,n=%%i*9
if !m! lss 100 if !n! gtr 100 set/a mn=809*%%i&set str=%%i
)
echo 809 × %str% = %mn%
pause
```
### How Many Peaches Were Picked on the First Day
```
@echo off
set m=1
set n=10
:lp
set/a m+=1
set/a m=%m%*2,n-=1
if %n% gtr 1 goto lp
echo %m% peaches were picked on the first day
pause
```
### Sort Numbers
```
@echo off
set/p var=Please enter numbers
set var=%var: =%
:lp
set .%var:~0,1% %random%=a
set var=%var:~1%
if not "%var%" == "" goto :lp
set/p =Sorted as:<nul
for /f "delims=.= " %%i in ('set .') do set/p =%%i<nul
echo.
pause
```
### Increasing Sequence
This is what I misunderstood. Let's modify it
```
@echo off
for /l %%i in (1,1,20) do set/a n+=%%i
echo %n%
pause
```
Last edited by terse on 2008-4-11 at 09:32 AM ]
|

简单!简单!再简单! |
|
2008-4-11 01:24 |
|
|
huajinghua
初级用户
 
积分 54
发帖 19
注册 2008-2-24
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
如果有算不出的,我就把C源码贴出来,哈哈
If there are problems that can't be solved, I'll post the C source code, haha
|
|
2008-4-11 14:02 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 10 楼』:
兔子问题(程序11):
使用 LLM 解释/回答一下
@echo off
set /p month=月份:
if %month% gtr 0 if %month% leq 2 echo 2只&pause&goto :eof
set /a month=%month%-2
set n=2&set m=2
:begin
set /a n=%n%+%m%
set /a w+=1
if %w% equ %month% echo %n%只&pause&goto :eof
set /a m=%m%+%n%
set /a v+=1
if %v% equ %month% echo %m%只&pause&goto :eof
goto begin
```@echo off
set /p month=Month:
if %month% gtr 0 if %month% leq 2 echo 2 only&pause&goto :eof
set /a month=%month%-2
set n=2&set m=2
:begin
set /a n=%n%+%m%
set /a w+=1
if %w% equ %month% echo %n% only&pause&goto :eof
set /a m=%m%+%n%
set /a v+=1
if %v% equ %month% echo %m% only&pause&goto :eof
goto begin
```
|

批处理之家新域名:www.bathome.net |
|
2008-4-11 16:04 |
|
|
s11ss
银牌会员
    
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
::判断素数【程序12】
@echo off
for /l %%a in (101,1,200) do call:j %%a
exit/b
:j
setlocal enabledelayedexpansion
set/a half=%1/2
for /l %%a in (2,1,!half!) do set/a r=%1%%%%a&if !r! equ 0 goto:eof
set/p=%1 <nul
```
::Determine Prime Number
@echo off
for /l %%a in (101,1,200) do call:j %%a
exit/b
:j
setlocal enabledelayedexpansion
set/a half=%1/2
for /l %%a in (2,1,!half!) do set/a r=%1%%%%a&if !r! equ 0 goto:eof
set/p=%1 <nul
```
|
|
2008-4-11 19:05 |
|
|
s11ss
银牌会员
    
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
::【程序25】 题目:求1+2!+3!+...+20!的和
@echo off&setlocal
for /l %%a in (1,1,20) do call:j %%a&set/a sum+=j
echo %sum%
pause
exit/b
:j
set/a j=1
for /l %%a in (1,1,%1) do set/a j*=%%a
```
::【Program 25】Title: Find the sum of 1 + 2! + 3! +... + 20!
@echo off&setlocal
for /l %%a in (1,1,20) do call:j %%a&set/a sum+=j
echo %sum%
pause
exit/b
:j
set/a j=1
for /l %%a in (1,1,%1) do set/a j*=%%a
```
|
|
2008-4-11 19:45 |
|
|
plp626
银牌会员
     钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
|
2008-4-11 20:02 |
|
|
s11ss
银牌会员
    
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
::【程序19】找“完数”
@echo off
echo Calculating...
for /l %%a in (1,1,1000) do (
setlocal enabledelayedexpansion
set/a sum=0
set/a a'=%%a-1
for /l %%b in (1,1,!a'!) do (
set/a t=%%a%%%%b
if !t! equ 0 set/a sum+=%%b
)
if !sum! equ %%a set/p=%%a <nul
endlocal
)
pause
::【Program 19】Find "Perfect Numbers"
@echo off
echo Calculating...
for /l %%a in (1,1,1000) do (
setlocal enabledelayedexpansion
set/a sum=0
set/a a'=%%a-1
for /l %%b in (1,1,!a'!) do (
set/a t=%%a%%%%b
if !t! equ 0 set/a sum+=%%b
)
if !sum! equ %%a set/p=%%a <nul
endlocal
)
pause
|
|
2008-4-11 20:24 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 15 楼』:
水仙花数(程序13):
使用 LLM 解释/回答一下
@echo off
for /l %%i in (100,1,999) do (
set str=%%i
setlocal enabledelayedexpansion
set a=!str:~,1!&set b=!str:~1,1!&set c=!str:~2,1!
set /a var=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !var! equ !str! echo !str!
endlocal
)
pause
Last edited by zw19750516 on 2008-4-11 at 10:40 PM ]
```@echo off
for /l %%i in (100,1,999) do (
set str=%%i
setlocal enabledelayedexpansion
set a=!str:~,1!&set b=!str:~1,1!&set c=!str:~2,1!
set /a var=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !var! equ !str! echo !str!
endlocal
)
pause```
Last edited by zw19750516 on 2008-4-11 at 10:40 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-11 20:41 |
|
|