473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Rotate an array by 2 places Ex:array a[]={0,1,2,3,4}; final : 3,4,0,1,2

2
Can any one write the code by using c programming for this query.

Thanks!
May 18 '10 #1
3 2008
jkmyoung
2,057 Expert 2GB
Yes, you can!

Is the rotation always 2 places? Are you using c or c++?
I suggest using 2 temporary variables to hold the last 2 variables, (3 and 4)
Then rotate the rest of the matrix. Then put values 3 and 4 back in.
May 18 '10 #2
ansark
2
@jkmyoung
Thank you very much for your reply. I am using C. cant we do without matrix this program ?
May 19 '10 #3
whodgson
542 512MB
There is a C++ generic algorithm 'rotate()' which performs this function found in the <algorithm> header.e.g.
Expand|Select|Wrap|Line Numbers
  1. char * s="ABCDEF";
  2. rotate(s,s+4,s+6);
  3. //prints EFABCD 
May 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rowan | last post by:
Greetings: I need some guidance. I have been using UDT's and arrays to hold information so I can easily display data and save it. I am in the process of building a new form and ran across a...
5
by: Hamish Dean | last post by:
Hi. I want to pass an array through a function. how do i do this? eg. void SomeFunction(){ int Array; Array = 1; Array = 2; Array = 3;
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
19
by: gaga | last post by:
I can't seem to get this to work: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *names; char **np;
2
by: raxitsheth | last post by:
I am using array in my progrm... is there any tool /tips so that i can convert my program to Dynamic Array...so that I can Add more Element to Array.... Code is around 4000 line 'C' (not C++)...
4
by: Bill Sun | last post by:
Hi, All I have a conventional question, How to create a 3 dimension array by C language. I see some declare like this: int *** array; int value; array = create3Darray(m,n,l);
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
22
by: guitarromantic | last post by:
Hey everyone, I run a site with staff-submitted reviews, and most of them are written by one author. However, we also do "multiple" reviews. Up until now I just had a userid for a 'Multiple'...
4
by: annmartinson | last post by:
yes, I've read and tried umpteen of the sort functions and still can't get it right. which one do I need??? ///////////////////////////////////////////// here is my array: $final = "fire";...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.