Tính tổng M chữ số cuối cùng của số nguyên N


Submit solution

Points: 1 (partial)
Time limit: 10.0s
Memory limit: 500M

Problem type

Nhập vào 1 số tự nhiên \(n*\) và nhập vào \(m\), sau đó tính tổng \(m\) các số tận cùng của \(n\).

Ví dụ :

Input
365 2
Output
11

Comments


  • 0
    DTC245200007 - Đào Minh Tâm  commented on Dec. 10, 2024, 2:06 p.m.

    include <bits/stdc++.h>

    using namespace std;
    int main(){
        int n, m;  cin >> n >> m;
        int tong = 0;
        while(m--){
            tong += n % 10;
            n /= 10;
        }
        cout << tong;
        return 0;
    }

  • 0
    DTC235201012 - Tạ Việt Hùng  commented on Dec. 8, 2024, 2:09 a.m.

    include <iostream>

    include <cmath>

    using namespace std; int main() { int n; int m; int a, b, c; cin >> n >> m; a = n/100; b = (n / 10) % 10;

    int sum = a + b + m;
    cout << sum;

    }