Given an integer number n (0<=n<10000), write a code returning the difference between the product of its digits and the sum of its digits.
이전 댓글 표시
Given an integer number n (0<=n<10000), write a code returning the difference between the product of its digits and the sum of its digits. For instance, if n=432 then the result is 4*3*2-(4+3+2) = 15.
답변 (1개)
SALAH ALRABEEI
2021년 6월 5일
편집: SALAH ALRABEEI
2021년 6월 5일
% check this
a = 4321;
b=str2num(num2str(a)');
diff = abs(sum(b)- prod(b))
댓글 수: 4
Walter Roberson
2021년 6월 5일
we do not encourage giving full solutions for homework, especially when the person has not made any attempts to solve the problem. Posting a homework question without even any discussion tends to suggest that the person is not interested in anything other than copying the solution without any work.
haneen yousef
2021년 6월 5일
SALAH ALRABEEI
2021년 6월 5일
totally agree. Noted.
Walter Roberson
2021년 6월 5일
That code seems to work when I test, except for 0 exactly.
For 0 exactly your Y would be 1 and your X would be 0 so you would get 1-0 = 1 as your solution, but for 0 exactly the product of the digits should be 0.
카테고리
도움말 센터 및 File Exchange에서 Signal Integrity Kits for Industry Standards에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!