Mọi người đánh giá xem giúp hai chương trình sau về mọi khía cạnh như coding style, tính tối ưu … và mọi người xem thích cái nao hơn với nhé.
Code 1
#include <iostream>
#include <conio.h>
using namespace std;
int Sum = 0;
int sumOddDigit(int n) {
if (n < 0) return -1;
int k = n % 10;
if (k != 0) {
if (k % 2 != 0) S += k;
return sumOddDigit(n / 10);
}
}
int main() {
S = sumOddDigit(101010);
cout << S;
_getch();
return 0;
}
code 2
#include <iostream>
#include <conio.h>
using namespace std;
int sumOddDigit(int n) {
if (n<0) return -1;
static int S = 0;
int i = n % 10;
n = n / 10;
if (i % 2 == 1) S += i;
if (n == 0) return S;
else return sumOddDigit(n);
}
void main() {
cout << sumOddDigit(101010);
_getch();
}
thanks!

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?