1 条题解

  • 0
    @ 2025-10-10 15:45:58

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int c;
        cin>>c;
    	int d = c % 10;
    	int b = c / 10 % 10;
    	int a = c / 100;
    	cout<<a + b + d<<endl; 
       return 0;
    }
    

    Pascal :

    var a,b,c,d:longint;
    begin
    read(a);
    b:=a mod 10;
    c:=a div 10 mod 10;
    d:=a div 100;
    write(c+b+d);
    end.
    

    Java :

    import java.util.Scanner;
    public class Main{
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int m = sc.nextInt();
      int s;
      int a = m/100%10;
      int b = m/10%10;
      int c = m/1%10;
      s=a+b+c;
      System.out.print(s);
    sc.close();
    }
    }
    
    

    Python :

    n=int(input())
    b=n//100
    s=n//10%10
    g=n%10
    print(b+s+g)
    
    • 1

    【入门】求任意三位数各个数位上数字的和

    信息

    ID
    277
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者