function [T]= MyFunction(N)tN=0;n=1;dSum=0;while dSum<N-1 tN=tN+n; n=n+1; dSum=0; num=tN; while num>0 dSum=dSum+mod(num,10); num=floor(num/10); end endT = tN;end
Your function needs to find the smallest triangle number whose digits add up to N and return this triangle number as T.
Example input:
N=10
Example output:
T=28
In this case, T=28 is the 7th triangle number (1+2+3+4+5+6+7=28), and the digits of T add up to (2+8)=10 = N
Best Answer