Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program 2: (Powers of 7): Using loops write a function named powersOf7 that prin

ID: 3804662 • Letter: P

Question

Program 2: (Powers of 7): Using loops write a function named powersOf7 that prints out powers of 7; that is 1, 7, 49, 343, … up to a limit n. n is a number that is read from the user using ‘input’ function. If n is a negative number, print out ‘Error: please input a positive number!’
    Example: powersOf7 (-3) ‘Error: please input a positive number!’
       powersOf7 (0) no (i.e. empty) output
       powersOf7 (20000)1, 7, 49, 343, 2401, 16807

PLEASE I WANT THIS PROGRAM TO BE WRITTEN IN MATLAB SO THAT IT WILL RUN CORRECTLY.

PLEASE GIVE ME AN ANSWER THAT NO ONE ELSE HAS WRITTEN

Explanation / Answer

program:

function [ ] = powerof7( n )
if(n<0)
disp('Error: please input a positive number!');
else
for i=0:n
fprintf('%d, ',power(7,i));
end
fprintf(' ');
end

end

Result:

>> powerof7(1)
1, 7, >> powerof7(1)
>> powerof7(1)
1, 7,
>> powerof7(-1)
Error: please input a positive number!
>> powerof7(100)
1, 7, 49, 343, 2401, 16807, 117649, 823543, 5764801, 40353607, 282475249, 1977326743, 13841287201, 96889010407, 678223072849, 4747561509943, 33232930569601, 232630513987207, 1628413597910449, 11398895185373144, 79792266297612000, 558545864083284032, 3909821048582987776, 2.736875e+19, 1.915812e+20, 1.341069e+21, 9.387480e+21, 6.571236e+22, 4.599865e+23, 3.219906e+24, 2.253934e+25, 1.577754e+26, 1.104428e+27, 7.730994e+27, 5.411696e+28, 3.788187e+29, 2.651731e+30, 1.856212e+31, 1.299348e+32, 9.095437e+32, 6.366806e+33, 4.456764e+34, 3.119735e+35, 2.183814e+36, 1.528670e+37, 1.070069e+38, 7.490483e+38, 5.243338e+39, 3.670337e+40, 2.569236e+41, 1.798465e+42, 1.258926e+43, 8.812479e+43, 6.168735e+44, 4.318115e+45, 3.022680e+46, 2.115876e+47, 1.481113e+48, 1.036779e+49, 7.257455e+49, 5.080219e+50, 3.556153e+51, 2.489307e+52, 1.742515e+53, 1.219760e+54, 8.538323e+54, 5.976826e+55, 4.183778e+56, 2.928645e+57, 2.050051e+58, 1.435036e+59, 1.004525e+60, 7.031676e+60, 4.922174e+61, 3.445521e+62, 2.411865e+63, 1.688306e+64, 1.181814e+65, 8.272697e+65, 5.790888e+66, 4.053622e+67, 2.837535e+68, 1.986275e+69, 1.390392e+70, 9.732745e+70, 6.812922e+71, 4.769045e+72, 3.338332e+73, 2.336832e+74, 1.635783e+75, 1.145048e+76, 8.015334e+76, 5.610734e+77, 3.927514e+78, 2.749260e+79, 1.924482e+80, 1.347137e+81, 9.429961e+81, 6.600972e+82, 4.620681e+83, 3.234477e+84,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote