回 帖 发 新 帖 刷新版面

主题:这条题目怎么做 大家帮帮可以没?~

题目如下:
   编写一个程序,计算s=a+aa+aaa+aaaa+...+aa....a的值,其中a是一个数字(例如2+22+222+2222+22222,共有5个数字相加),要求输入数字a和相加的数的个数n

我想了很久想不出来啊

回复列表 (共11个回复)

沙发

这还不简单!
dim 循环数字 as string
dim 个数 as long
dim i as integer
dim 得数 as long
input 循环数字
input 个数
for i = 1 to 个数
得数=得数+VAL(STRING(i,循环数字))
next
?得数

板凳

倒 可以用qbasic做没?~

3 楼

解法我想出来但是编译中出现错误 请问我哪里错了
input "a=";a
input "n=";n
i=0
x=1
while x<=n
s=a+a*10^i
i+i+1
x=x+1
wend
print "s=";s
end
就是这样 我昨晚想了出来 但是运行过程中运行不了

4 楼

cls
input "a=";a
input "s=";s
m=a
for i=0 to n-1
   if i=0 then a=a else a=a*10+m
print a;
s=s+a
next i
print
print s
end

5 楼

或许 技术含量不高,但是 能完成 你的那道题。!!

6 楼

input "a=";a
input "n=";n
i=0
x=1
while x<=n   '[color=008000]这个语句体应该用 FOR[/color]
s=a+a*10^i   '[color=008000]你确认 a 是一位数没有?而且这个得数有点问题喔,只是 a00000a 而已。[/color]
i+i+1        '[color=008000]你的意思是不是 i=i+1 ?[/color]
x=x+1        
wend
print "s=";s
end

我只好向你动一动刀子了:
input "a=",a
input "n=",n
if a>10 or a<1 then end
for x=1 to n
  for i=1 to x
    s=s+a*10^i
  next
next
print "s=";s

还是用1楼的办法较好:
input "a=",a
input "n=",n
if a>10 or a<1 then end
for x=1 to n
    s=s+val(string$(x,48+a))
next
print "s=";s

我倒是觉得中间那一句还可以改一改的:
s=s+a*10^x*x

7 楼

好多都看不懂啊 我的课本还没教到for语句 还有4楼的cls是什么来的~?~?

8 楼

肯定a是一个数的 0-9的数字```
你试试有没其他简单的方法~~我书本根本没教到for语句还有很多我都没见过``
就是叫运用所学知识```我郁闷了现在

9 楼

cls
input a,n
dim k(n),k$(n)
c$=str$(a)
k$(1)=c$:k(1)=a
for i = 2 to n
k$(i)=a$(i-1)+c$
k(i)=val(k$(i))
next i
for i = 1 to n
if i<n then print k(i);"+";
if i=n then pritn k(i);"=";
b=a(i)+b
next i
print b
end

10 楼

暑假当中,妈妈让小慧帮忙修改英文资料,英文中还有一些统计数据(统计数据都是正整数,而且其前、后都有空格)。妈妈说:如果文档结尾处有“end”,则应当删除,文中所有的统计数据都要加上一个正整数m。你能编程序完成小慧的任务吗?
输入:m
      待修改后的文档(字符串)
输出:修改后的文档(字符串)
例如:输入:13
            There are 45 students in 32class.end
      输出:There are 58 students in 32class.

我来回复

您尚未登录,请登录后再回复。点此登录或注册