回 帖 发 新 帖 刷新版面

主题:请问:有10个整数,求出奇数之各、偶数之和。程序应该怎么编啊?

有10个整数,求出奇数之各、偶数之和。

回复列表 (共7个回复)

沙发

defint a-z
dim num(10)
sum1=0:sum2=0
for i=1to10
input num(i)
if num(i) mod 2=0 then sum1=sum1+1 else sum2=sum2+1
next
print sum1,sum2

板凳

for i=1 to 10
input x
if x mod 2=0 then s1=s1+1 else s2=s2+1
next i
? "ou";s1,"qi";s2
end

3 楼

[em18]
你是要求奇数个数和偶数个数,还是分别求所有奇数之和,所有偶数之和?

4 楼

cls
for i=1 to 10 then
input "zs=";x
if s mod 2 =0 then s1=s1+x else s2=s2+x
next i
print "os=";s1;"js=";s2
end
不知道对不对,不对请给出指导。谢谢。

5 楼

cls
dim x as integer
for i=1 to 10
input "zs=";x
if x mod 2=0 then s1=s1+x else s2=s2+x
next i
print "os=";s1,"js=";s2
end
这是标准答案,呵呵!

6 楼

cls
dim a(10)
for i=1 to 10
 input a(i)
next i
for i=1 to 10
 if a(i) mod 2=0 then a=a+a(i) else b=b+a(i)
next i
? a,b

7 楼

cls
for i=1 to 10
input a
if a mod 2=0 then o=o+1 else j=j+1
next i
print "偶数:";o,"奇数:";j
end

我来回复

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