21 条题解

  • 7
    @ 2022-12-23 15:20:25
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int x;
        cin >> x;
        int sum = 0;
        while (x > 0)
        {
            sum += x % 10;
            x /= 10;
        }
        cout << sum;
        return 0;
    }
    

    很简单很简单很简单很简单很简单很简单很简单很简单的一道题。

    • 7
      @ 2021-11-20 13:42:22

      C++ 中求商的符号为 / ,C++ 中求余的符号为 %

      取个位数x%10

      取十位数 先去掉个数再取余 x/10%10

      取百位数 去掉个位十位 x/100

      • 3
        @ 2024-1-27 10:48:04

        自己什么实力自己清楚 上代码~

        #include<iostream>
        using namespace std;
        int main()
        {
            int n,a,b,c;
            cin>>n;
            a = n*0.01;
            b = n*0.1-10*a;
            c = n-100*a-10*b;
            cout<<a+b+c;
            return 0;
        }
        
        • @ 2024-3-26 20:38:06

          你你你你你你你你你你个大傻………………………………………………………………

        • @ 2024-3-26 20:38:29

          必须差评

      • 1
        @ 2023-8-30 9:48:16

        //已AC,请放心食用,记得五星好评❤️

        #include <iostream>
        using namespace std;
        int main(int x,int g,int s,int b){
            cin >> x;
            b = x / 100;
            s = x % 100 / 10;
            g = x % 10;
            cout << b + s + g;
            return 0;
        }
        
        • 0
          @ 2024-4-14 20:50:32
          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
              int x;
              cin >> x;
              int sum = 0;
              while (x > 0)
              {
                  sum += x % 10;
                  x /= 10;
              }
              cout << sum;
              return 0;
          }
          
          
          • 0
            @ 2024-1-17 12:53:45
            #include <iostream>
                using namespace std;
                int main()
                {
                    int n,a,b,c;
                    cin >> n;
                    a=n/100;
                    b=(n-a*100)/10;
                    c=n-a*100-b*10;
                    cout << a+b+c;
                    return 0;
                }
            
            • 0
              @ 2022-10-9 21:12:35

              小号第二题。

              #include <iostream>
              using namespace std;
              int main()
              {
                  int n,b,s,g;
                  cin >> n;
                  b=n/100;
                  s=n%100/10;
                  g=n%10;
                  cout << b+s+g;
                  return 0;
              }
              
              • 0
                @ 2022-8-17 19:14:00

                写个while循环不停拆再加即可:

                #include <iostream>
                #include <cstdio>
                using namespace std;
                int f(int a)//定义一个函数,来计算每一位
                {
                    int temp=a,sum=0;
                    while (temp)//当temp大于0就一直拆
                    {
                        sum+=temp%10;//加上temp的末位
                        temp/=10;
                    }
                    return sum;
                }
                int main()
                {
                    int x;
                    cin>>x;
                    cout<<f(x)<<endl;
                    return 0;
                }
                
                • 0
                  @ 2022-8-6 16:28:42

                  直接上代码吧

                  #include <bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                      int x, sum = 0;
                      cin >> x;
                      while (x != 0)
                      {
                          sum += x % 10;
                          x /= 10;
                      }
                      cout << sum << endl;
                      return 0;
                  }
                  
                  • 0
                    @ 2022-6-11 21:15:59

                    远古时期的代码 被我翻出来啦...

                    #include <bits/stdc++.h>
                    using namespace std;
                    int main(){
                    	//所有小于等于1234567891的数都可
                    	int n,i = 0;
                    	scanf("%d",&n);//scanf("输入控制符", 输入参数) %d为键盘输入的字符(转换为十进制)  &n为地址(n) 
                    	while(n > 0){//while循环 
                    		i += n%10;//更新i 
                    		n /= 10;//更新n 
                    	}
                    	printf("%d",i);//输出结果i 
                    	return 0;
                    }
                    

                    凑合看看吧

                    • 0
                      @ 2022-5-15 14:51:46

                      首先呢,先拿出我们整数的求商符号:“/”,注意怎么去求数字和。 上代码!

                          #include <iostream>
                          using namespace std;
                          int main()
                          {
                              int n,a,b,c;//老熟人了,不想说
                              cin >> n;//也不想说
                              a=n/100;//求百位
                              b=(n-a*100)/10;//求十位
                              c=n-a*100-b*10;//个位
                              cout << a+b+c;//输出数字和
                              return 0;
                          }
                      

                      日常第二题,嗨害嗨~~~

                      • -1
                        @ 2024-1-17 12:53:14
                        #include <iostream>
                            using namespace std;
                            int main()
                            {
                                int n,a,b,c;
                                cin >> n;
                                a=n/100;
                                b=(n-a*100)/10;
                                c=n-a*100-b*10;
                                cout << a+b+c;
                                return 0;
                            }
                        
                        • -1
                          @ 2023-11-19 14:20:03

                          #include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; int sum = 0; while (x > 0) { sum += x % 10; x /= 10; } cout << sum; return 0; }

                          • -1
                            @ 2023-11-2 16:36:34

                            好简单

                            #include<bits/stdc++.h>
                            using namespace std;
                            int main(){
                            	int a;
                            	cin>>a;
                            	int s=0; 
                            	while(a>0){
                            		s+=a%10;
                            		a/=10; 
                            	} 
                            	cout<<s; 
                                return 0;
                            }
                            
                            • -1
                              @ 2023-8-30 18:53:14

                              这道题可以用数位拆分的方法:

                              1. 使用 while 循环, 条件是这个数大于0。 ( 因为这个数小于等于 0 时就表示全部数位循环完了 )
                              2. 接着用这个数对十取余, 得到的商就是一个数位, 增加到计数变量中。
                              3. 再把这个数除以10, 让数位变成下一个数位。 以上就是做题步骤, 下面是根据思路写的源代码: ( 注意: 根据上面思路实在想不出来才可以看!!! )
                              #include <bits/stdc++.h>
                              using namespace std;
                              int main() {
                                  int sum = 0;
                                  int x;
                                  cin >> x;
                                  while(x > 0) {
                                      sum += x % 10;
                                      x /= 10;
                                  }
                                  cout << sum;
                              }
                              
                              </span>
                              • -1
                                @ 2023-8-17 12:41:57

                                `

                                #include <bits/stdc++.h>
                                using namespace std;
                                
                                int main(){
                                	int n,a,b,c;
                                	cin>>n;
                                	a=n/100;
                                	b=n/10%10;
                                	c=n%10;
                                	cout<<a+b+c;
                                	return 0;
                                }
                                
                                • @ 2023-8-17 12:43:38

                                  直接上代码,已AC,放心食用👍

                              • -1
                                @ 2023-8-16 18:39:21

                                这道题没有人用字符?👀️

                                本题第一道字符题解来辣

                                上代码🚀️

                                #include <bits/stdc++.h>
                                using namespace std;
                                int s;//初始化s
                                int main()
                                {
                                    string x;
                                    cin >> x;
                                    for (int i = 0; i < 3; i++) s += x[i] - '0';//遍历字符串,然后记得把字符转换成整数(字符变量 -‘0’)
                                    cout << s;
                                    return 0;
                                }
                                

                                比较啰嗦,AC放心食用👍

                                • -1
                                  @ 2023-5-31 17:02:53
                                  #include <bits/stdc++.h>
                                  using namespace std;
                                  int x, s;
                                  int main()
                                  {
                                      cin >> x >> s;
                                      s = x / 100 + x / 10 % 10 + x % 10;
                                      cout << s;
                                      return 0;
                                  }
                                  
                                  • -2
                                    @ 2024-4-14 20:51:15

                                    🎉️

                                    • -2
                                      @ 2024-3-7 15:42:06

                                      #include<bits/stdc++.h> using namespace std; int a,sum; int main(){ cin>>a; while(a){ sum+=a%10; a/=10; } cout<<sum; return 0; }

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

                                      信息

                                      ID
                                      20
                                      时间
                                      1000ms
                                      内存
                                      16MiB
                                      难度
                                      5
                                      标签
                                      递交数
                                      1764
                                      已通过
                                      661
                                      上传者