###### 【隐身守候】

2020-06-02 00:32 阅读 84

# c语言初学者，请各位大佬帮忙！！！

Private Sub Form_click()
Dim s As Integer
Dim x As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
s = 0
x = 100
Do While x <= 999
a = Int(x / 100)
b = Int(x / 10) - a * 10
c = x - a * 100 - b * 10
If Then s = s + x
x = x + 1
Loop
Print s
End Sub

Private Sub Command1_Click()
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
n = a * 100 + b * 10 + c
m = a * a * a + b * b * b + c * c * c
If ____________ Then
s = s + n
End If
Next c
Next b
Next a
Print s
End Sub

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

#### 1条回答默认 最新

• 已采纳
``````#include <stdio.h>

int f(int n)
{
int a = n % 10;
int b = (n / 10) % 10;
int c = n / 100;
/* return (a + b) % 10 == c &&
((a % 2 == 1 ? a : 0) + (b % 2 == 1 ? b : 0) + (b % 2 == 1 ? b : 0) == c);
*/
return (a + b) % 10 == c && c % 2 == 1;
}

int main()
{
int sum = 0;
for (int i = 111; i <= 999; i++)
{
if (f(i)) { sum += i; printf("%d ", i); }
}
printf("\n%d", sum);
return 0;
}
``````

129 138 147 156 165 174 183 192 303 312 321 330 349 358 367 376 385 394 505 514 523 532 541 550 569 578 587 596 707 716 725 734 743 752 761 770 789 798 909 918 927 936 945 954 963 972 981 990
27264

求所有水仙花数之和，这个必须限定几位数，因为水仙花数有无数多个。求和无意义
下面是3位的，

``````#include <stdio.h>
int main()
{
int a,b,c;
int sum = 0;
for(int i=100; i<999; i++){
a = i/100;
b = i%100/10;
c = i%10;
if(a*a*a + b*b*b + c*c*c == i){
printf("%d ", i);
sum += i;
}
}
printf("\n%d\n", sum);
return 0;
}
``````

153 370 371 407
1301

# 问题解决的话，请点下采纳

点赞 1 评论 复制链接分享