一道qbasic的编程题!!!!!!!!!!!!!!!!!求助!!
来源:百度知道 编辑:UC知道 时间:2024/04/28 20:30:39
1到n的数字和为1990,求n=?
(do while)
不是这样,比如说:1到15的数字和:
1+2+3+4+5+6+7+8+9+1+0+1+1+1+2+1+3+1+4+1+5
再给一条公式
(位数)=int(log(n)/log(10))+1
(do while)
不是这样,比如说:1到15的数字和:
1+2+3+4+5+6+7+8+9+1+0+1+1+1+2+1+3+1+4+1+5
再给一条公式
(位数)=int(log(n)/log(10))+1
s=0
do while s<1990
n=n+1:p=n
do while p<>0
s=s+p mod 10
p=p\10
loop
loop
print n
r = 1990
Do
d = d + 1
s = s + 1
If d = 10 Then
c = c + 1
d = 0
End If
If c = 10 Then
b = b + 1
c = 0
End If
If b = 10 Then
a = a + 1
b = 0
End If
h = h + a + b + c + d
If h = r Then GoTo 1000
Loop
1000 Print s
其中 s就是你要的n!
我是在VB++6。0上写的你在QB上试试吧?
很不易哟??!!!
更改r的值就可以解决其它和的问题了(不要大于9999哟)
i=1
s=0
do while true
s=s+i
if s>=1990 then exit
i=i+1
loop
print(i)
CLS
S=1990
DO WHILE S<>0
A=A+1
A$=STR$(A)
L=LEN(A$)
FOR I=1 TO L
S=S-VAL(MID$(A$,I,1))
NEXT I
LOOP
PRINT A