Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day62 #100DaysChallenge- Matlab Loops| Generate and Sum the Series :1

 #Day62-Generate and Sum the Series
Task:

Write a code to  find if the sum of series
Generate the series like this 1,10,100,1000,1000
Note:Take user Input for number of digit.
Sum=11111

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code


function sum_series=sumofseries(n)
b=1;
t=1;
sum_series=0;
while n>=1
    sum_series=(b*t)+sum_series;
    t=t*10;
  
end
end

Sample Input and Output
>> sumofseries(9)

ans =

   111111111

>> sumofseries(11)

ans =

   1.1111e+10

>> sumofseries(5)

ans =

       11111

>> sumofseries(4)

ans =

        1111
Click here for Video Description



Free Codes: youtube.com/castorclasses



Live Support: t.me/matlabirawen


No comments

Popular Posts