VB:编写子过程,对指定正整数n计算并输出各个位数之和.如果n=12 345,那么1+2+3+4+5=15

问题描述:

VB:编写子过程,对指定正整数n计算并输出各个位数之和.如果n=12 345,那么1+2+3+4+5=15

sub calc(n as long) as longdim strNum as stringdim i as longstrNum=format(n)for i=1 to len(strNum)nSum=nSum+val(mid(strNum,i,1))next iprint nSumend sub