Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int sochuso(int n) {
- if (n<10 ) {
- if (n % 3 == 0) {
- return n;
- }
- else {
- return 0;
- }
- }
- else {
- if ((n % 10) % 3 == 0) {
- return n % 10 + sochuso(n / 10);
- }
- else {
- return sochuso(n / 10);
- }
- }
- }
- int nhapso(int n) {
- if (n < 0) {
- return -1;
- }
- else
- {
- return sochuso(n);
- }
- }
- void main() {
- int n;
- cout << "nhap n :";
- cin >> n;
- cout << nhapso(n);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement