VB程序设计的一道题,找出100以内能被3整除的所有数之和,并把值保存在一维数组中以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
VB程序设计的一道题,找出100以内能被3整除的所有数之和,并把值保存在一维数组中
Dim a() As Integer '存放能被3整除数的动态数组dim sum as Integer '存放和 Sub GetNumber() Dim i As Integer Dim num As Integer sum = 0 num = 0 For i = 1 To 100 ' 如果一个数能被3整除 If i Mod 3 = 0 Then '求和 sum = sum + i '将这个数保存到动态数组中 ReDim Preserve a(0 To num) As Integer a(num) = i num = num + 1 End If Next '打印出和 Debug.Print "和为:" + Format(sum) '打印出数组中所有能被3整除的数 For i = 0 To num - 1 Debug.Print a(i) NextEnd Sub
求10000以内能被3整除的所有数之和的程序设计?
Private Sub Command1_Click() For i = 3 To 9999 Step 3 s = s + i Next i Print "sum=" & s End Sub
用js写一个程序找出1000以内能被3整除的数保存在数组a中、能被4整除的数保存
var a = [], b = [];for(var i = 0; i < 1000; i ++){ if(i % 3 == 0){ a.push(i); }else if(i % 4 == 0){ b.push(i); }}
VB 将1~500之间能被7或11整除 但不被3和4整除的所有整数存放在一维数组中 并输出
Private Sub Command1_Click()
Dim i%, j%
Dim a() As Integer
For i = 1 To 500
If (i Mod 7 = 0 Or i Mod 11 = 0) And i Mod 4 <> 0 And i Mod 3 <> 0 Then
j = j + 1
ReDim a(j) As Integer
a(j) = i
Print a(j);
End If
Next
End Sub
C程序设计题 一维数组
#include "stdio.h"
#include "math.h"
int main()
{
int i,d[20],t[20],j,k,n,mark,temp;
printf("输入20个整数:");
n=0;k=0;
for(i=0;i<20;i++)
{
scanf("%d",&d[i]);输入整数(20个)
判断d[i]是否是素数
mark=0;
for(j=2;j
{
if(d[i]%j==0)
{
mark=1;
break;
}
}
if(mark==0)是素数时存入新的数组
{
t[k++]=d[i];
}
}
对素数数组进行排序
for(i=0;i
{
for(j=k-1;j>i;j--)
{
if(t[j]
{
temp=t[j];t[j]=t[j-1];t[j-1]=temp;
}
}
}
for(i=0;i
printf("%d ",t[i]);
}
VB程序设计:从键盘输入10个互不相同的100以内的整数,放在一维数组中。
'改别人的程序费脑,改你的程序费粮食!
Private Sub Form_Click()
Dim a(10) As Integer
Dim i As Integer
Dim r As Integer
Dim x As Integer
Dim max As Integer
Dim min As Integer
Randomize
Do While i <= 9
a(i) = Val(InputBox("请输入第" & i + 1 & "个100以内的整数"))
If a(i) > 100 Or a(i) < 0 Then
MsgBox "请输入100以内的整数"
Else
For r = 0 To i - 1
If a(i) = a(r) Then
MsgBox "输入的数不能有重复"
Exit For
End If
Next
If r = i Then i = i + 1
End If
Loop
max = 0
min = 100
For r = 0 To 9
If a(r) > max Then max = a(r)
If a(r) < min Then min = a(r)
Next
Do
f = 1
x = Int(Rnd * 100)
For r = 0 To 9
If Not (min < x And max > x And x <> a(r)) Then
f = 0
Exit For
End If
Next
If f = 1 Then
MsgBox x
Exit Do
End If
Loop
End Sub
编一程序求100以内能被3整除的所有数之和
一句就搞定的程序:
#include
void main()
{
cout<
求一维数组能被3和5整除的和
package .jk;public class ArrayUtil { public static void main(String[] args) { System.out.println("数组中能被3或者5整除的数的和等于" + arrTestSum()); } public static int arrTestSum() { int sum = 0 ; int[] array = {-1,-100,55,66,1092,3}; for(int i : array) { if(i%3==0||i%5==0) { sum+=i; } } return sum; }}或者
package .jk;public class ArrayUtil { public static void main(String[] args) { int[] array = {-1,-100,55,66,1092,3}; System.out.println("数组中能被3或者5整除的数的和等于" + arrTestSum(array)); } public static int arrTestSum(int[] array ) { int sum = 0 ; for(int i : array) { if(i%3==0||i%5==0) { sum+=i; } } return sum; }}
vfp程序设计,用双重循环求100以内能被6整除的数之和
SET TALK OFFSTORE 0 TO mFOR i=1 TO 100IF MOD(i,6)=0 m=m+iENDIFNEXT i? '100以内能被6整队的自然数之和为 '+ALLTRIM(STR(m))SET TALK ONRETURN
C语言编程:一维数组程序设计
#include
main()
{
char arr[],temp='';
int i = 0,w_count = 0,c_count = 0,n_count = 0,w_count_now = 0,c_count_now = 0,n_count_now = 0;
printf("输入一串字符:");
scanf("%s",arr);
while(arr[i] != '\0')
{
if(((int)arr[i] >= 65 && (int)arr[i] <= 90) or ((int)arr[i] >= 97 && (int)arr[i] <= 122))
{
w_count++;
}
else if((int)arr[i] >= 48 && (int)arr[i] <= 57)
{
n_count++;
}
else c_count++;
i++;
}
w_count_now = 0;
c_count_now = w_count;
n_count_now = w_count + c_count;
i = 0;
while(arr[i] != '\0')
{
if(((int)arr[i] >= 65 && (int)arr[i] <= 90) or ((int)arr[i] >= 97 && (int)arr[i] <= 122))
{
temp = arr[w_count_now];
arr[w_count_now] = arr[i];
arr[i] = temp;
w_count_now++;
}
else if((int)arr[i] >= 48 && (int)arr[i] <= 57)
{
temp = arr[n_count_now];
arr[n_count_now] = arr[i];
arr[i] = temp;
n_count_now++;
}
else
{
temp = arr[c_count_now];
arr[c_count_now] = arr[i];
arr[i] = temp;
c_count_now++;
}
i++;
}
printf("调整后的字符串为:%s",arr);
}
分页:
1
23