Question

Matlab: Write a program that calculates and stores in a vector the results of the sum...

Matlab:

Write a program that calculates and stores in a vector the results of the sum 9 + 99 + 999 + 9999 + .... for any number of components.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM FOR GIVEN QUESTION:

%matlab program to find the sum of
%the series 9+99+999+9999+....
n=input('enter a number upto which you need sum:');
sum=0;
vector=[];
j=9;
for i=1:n
    sum = sum + j;
    vector=[vector j];
% Appending a 9 at the end
    j = (j * 10) + 9;
end
disp(vector)
fprintf('sum of %d numbers is:%d\n',n,sum)

OUTPUT:

>> HomeworkLib
enter a number upto which you need sum:4
           9          99         999        9999

sum of 4 numbers is:11106

Add a comment
Know the answer?
Add Answer to:
Matlab: Write a program that calculates and stores in a vector the results of the sum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT