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

Search This Blog

#Day54 #100DaysChallenge- Matlab Loops|Swapping Numbers

#Day54-Swapping Numbers
Task:

Write a code to swap three numbers
swap(13,2,7)
After Swap:2,7,13

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


Matlab code
function  swapelements(x,y,z)
temp=0;
temp=x;
x=y;
y=z;
z=temp;

fprintf('New X Y Z VALUE %d %d %d',x,y,z);
end


 Sample Input and Output
>> swapelements(6,7,8)
New X Y Z VALUE 7 8 6
>> swapelements(13,2,7)
New X Y Z VALUE 2 7 13

Click here for Video Description


No comments

Popular Posts

Followers