c语言初学者,请各位大佬帮忙!!!

求三位数中,个位数字与十位数字之和除以10所得的余数是百位数字,且百位数字是奇数的数的和。
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

求所有水仙花数之和(所谓水仙花数是指一个三位十进制数,该数的各位数字立方之和等于该数本身。例如371是一个水仙花数,因为3^3+7^3+1^3=371)。
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

问题解决的话,请点下采纳

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐