编程求在四位数的奇数中,所有各位数字之和是25的倍数的数之和。(1298515)
Private Sub Form_Click()
Dim m%, a%, b%, c%, d%, s&
s = 0
FontSize = 14: FontBold = True
Print: Print: Print
For m = 1001 To 9999 Step 2
a = Int(m / 1000)
b = Int((m - 1000 * a) / 100)
c = Int((m - 1000 * a - 100 * b) / 10)
d = m Mod 10
If Then s = s + m
Next m
Print s
End Sub
编程求在四位数的偶数中,所有各位数字之积是25的倍数的数之和。(555500)
Private Sub Command1_Click()
sum = 0
For i = 1000 To 9999 Step 2
d1 = i Mod 10
d2 = (i \ 10) Mod 10
d3 = (i \ 100) Mod 10
d4 = i \ 1000
d = d1 * d2 * d3 * d4
If Then sum = sum + i
Next i
Print sum
End Sub
#include <stdio.h>
int sum(int n)
{
int s = 0;
while (n > 0)
{
s += n % 10;
n /= 10;
}
return s;
}
int main()
{
int s = 0;
for (int i = 1111; i <= 9999; i++)
{
if (i % 2 == 1 && sum(i) % 25 == 0)
s += i;
}
printf("%d\n", s);
return 0;
}
1298515
Press any key to continue . . .
#include <stdio.h>
int sum(int n)
{
int s = 0;
while (n > 0)
{
s += n % 10;
n /= 10;
}
return s;
}
int main()
{
int s = 0;
for (int i = 1111; i <= 9999; i++)
{
if (i % 2 == 0 && sum(i) % 25 == 0)
s += i;
}
printf("%d\n", s);
return 0;
}
1112360
Press any key to continue . . .
你的结果是错的,四位数的偶数中,所有各位数字之积是25的倍数的数如下。你自己对照下。
1798 1888 1978 1996 2698 2788 2878 2896 2968 2986 3598 3688 3778 3796 3868 3886
3958 3976 3994 4498 4588 4678 4696 4768 4786 4858 4876 4894 4948 4966 4984 5398
5488 5578 5596 5668 5686 5758 5776 5794 5848 5866 5884 5938 5956 5974 5992 6298
6388 6478 6496 6568 6586 6658 6676 6694 6748 6766 6784 6838 6856 6874 6892 6928
6946 6964 6982 7198 7288 7378 7396 7468 7486 7558 7576 7594 7648 7666 7684 7738
7756 7774 7792 7828 7846 7864 7882 7918 7936 7954 7972 7990 8098 8188 8278 8296
8368 8386 8458 8476 8494 8548 8566 8584 8638 8656 8674 8692 8728 8746 8764 8782
8818 8836 8854 8872 8890 8908 8926 8944 8962 8980 9088 9178 9196 9268 9286 9358
9376 9394 9448 9466 9484 9538 9556 9574 9592 9628 9646 9664 9682 9718 9736 9754
9772 9790 9808 9826 9844 9862 9880 9916 9934 9952 9970