SourceCodePoint
Wednesday, 6 July 2016
Write a MATLAB program for Sum of Digits using while loop
Code:
clear
clc
n = input(
'Enter the n value : \n'
);
s = 0;
while
n>0
s = s + mod(n,10);
n = floor(n/10);
end
fprintf(
'Sum of digit : %d\n'
,s);
Output:
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment