Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Pure VPN - Up to 27 Months
vgp
Updated:
Today at 8:10 AM
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Write a C++ Program...
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="viraj_slk" data-source="post: 7369128" data-attributes="member: 51932"><p><span style="font-size: 12px">it's been quite a while since i had to write a c++ program so I cannot remember the c++ syntax's correctly. that's y i hoped u would b able to write the program urself <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /> as the problem is already solved. but it seems u still don't get the solution. i will try to explain a bit more as i can. </span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">I hope u know arrays and for loop.</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">okay lets say the starting array is:</span></p><p><span style="font-size: 12px">arr[1, 2, 3, 4, 5]</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"><strong>Always remember that arrays start with 0</strong>. So the 0th element in the array is 1.</span></p><p><span style="font-size: 12px">arr[0] => 1</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">now if the user has input 3 as the number of positions to rotate clockwise, you have to move number 1 ,three positions to the left (which is clockwise) in the array.</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">Again remember the position of number 1 is 0. so when u move left by 3 positions the new position is: 0 + 3 => 3</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">So what number is currently in the 3rd positions of the current array?</span></p><p><span style="font-size: 12px">arr[3] => 4</span></p><p><span style="font-size: 12px">it is number 4 (again and again this is because the first position of the array is <strong>position 0</strong>). </span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">so when u move number 1 (which is in the 0th position at start) three time to the left, the new position of number one is : 0 + 3 => 3</span></p><p><span style="font-size: 12px">so number 1 should be moved to where number 4 is at right now.</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">And that is what exactly the following formula does. at it is the solution to the problem.</span></p><p><span style="font-size: 12px">i => symbolizes the position of number 1 which is 0 in our case</span></p><p><span style="font-size: 12px">x => symbolizes the number of positions to rotate, which is 3 in our case</span></p><p><span style="font-size: 12px">n => symbolizes the number of values in the array. which is 5 in this case</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">p=> finally.. 'p' symbolizes the new position of the value (which is going to be 3! as i explained )</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">so.. the formula is:</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">p = (i + x)%n; </span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">let put values into it (% stands for modulus operator. u shud know it, or google):</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">p = (0 + 3) % 5 </span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">p = 3 % 5 so..</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">p = 3 (.. our new position for number 1 is 3)</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">put the rest of the values into this formula and try urself. this couldn't be more easier now.</span></p><p><span style="font-size: 12px"></span></p></blockquote><p></p>
[QUOTE="viraj_slk, post: 7369128, member: 51932"] [SIZE="3"]it's been quite a while since i had to write a c++ program so I cannot remember the c++ syntax's correctly. that's y i hoped u would b able to write the program urself :) as the problem is already solved. but it seems u still don't get the solution. i will try to explain a bit more as i can. I hope u know arrays and for loop. okay lets say the starting array is: arr[1, 2, 3, 4, 5] [B]Always remember that arrays start with 0[/B]. So the 0th element in the array is 1. arr[0] => 1 now if the user has input 3 as the number of positions to rotate clockwise, you have to move number 1 ,three positions to the left (which is clockwise) in the array. Again remember the position of number 1 is 0. so when u move left by 3 positions the new position is: 0 + 3 => 3 So what number is currently in the 3rd positions of the current array? arr[3] => 4 it is number 4 (again and again this is because the first position of the array is [B]position 0[/B]). so when u move number 1 (which is in the 0th position at start) three time to the left, the new position of number one is : 0 + 3 => 3 so number 1 should be moved to where number 4 is at right now. And that is what exactly the following formula does. at it is the solution to the problem. i => symbolizes the position of number 1 which is 0 in our case x => symbolizes the number of positions to rotate, which is 3 in our case n => symbolizes the number of values in the array. which is 5 in this case p=> finally.. 'p' symbolizes the new position of the value (which is going to be 3! as i explained ) so.. the formula is: p = (i + x)%n; let put values into it (% stands for modulus operator. u shud know it, or google): p = (0 + 3) % 5 p = 3 % 5 so.. p = 3 (.. our new position for number 1 is 3) put the rest of the values into this formula and try urself. this couldn't be more easier now. [/SIZE] [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom