asked 135k views
2 votes
write a matlab program in a script file that finds a positive integer n such that the sum of all the integers 1 2 3 n is a number between 100 and 1,000 whose three digits are identical. as output, the program displays the integer n and the corresponding sum.

asked
User Froehli
by
8.9k points

1 Answer

1 vote

Answer:

%% Positive Integer between 100 and 1,000 with Identical Digits

% Initialize variables

n = 0;

sum = 0;

% Loop until an integer is found that meets the requirements

while sum < 100 || sum > 1000 || length(unique(num2str(sum))) ~= 1

n = n + 1;

sum = sum + n;

end

% Print the integer and corresponding sum

fprintf('The integer is %d and the sum is %d.\\', n, sum);