Rotate an array by 2 places


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rotate an array by 2 places
# 1  
Old 05-18-2010
Rotate an array by 2 places

I have an array a[]={0,1,2,3,4}
The out put should be: 3,4,0,1,2

Please can any body write code for this program?

Thanks!
# 2  
Old 05-18-2010
Quote:
Originally Posted by ansar basha.k
Please can any body write code for this program?!
No! Why should anyone?

What attempts have you made already?

Is this a homework question?
# 3  
Old 05-18-2010
No, it is not a home work question.
# 4  
Old 05-18-2010
Code:
$ cat ArrTest
set -A a 0 1 2 3 4

echo A is:
printf "%s\n" ${a[@]}

set -A a $(printf "%s\n" ${a[@]} | sed '1,3{H;d;}; $G')

echo "--------"

echo A is:
printf "%s\n" ${a[@]}




$ ./ArrTest
A is:
0
1
2
3
4
--------
A is:
3
4
0
1
2

# 5  
Old 05-19-2010
Scotton thank you so much for your reply....i need this program in C programming language not in unix.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum the fields with 6 decimal places - getting only 2 decimal places as output

I used the below script to Sum up a field in a file based on some unique values. But the problem is when it is summing up the units, it is truncating to 2 decimals and not 6 decimals as in the input file (Input file has the units with up to 6 Decimals – Sample data below, when the units in the 2... (4 Replies)
Discussion started by: brlsubbu
4 Replies

2. UNIX for Dummies Questions & Answers

Logs do not rotate

My problem: Both access and error logs do not rotate any more and get really large. They are located here: /srv/www/+vHost name here+/logs/ Configuration seems to be here: /etc/logrotate.conf => looks OK, including "size 10M" to avoid large files (/etc/logrotate.d => is empty) manually... (4 Replies)
Discussion started by: floko
4 Replies

3. Shell Programming and Scripting

Log rotate

Hi, I have below script in logrotate.d to rotate logs. logs are not rotating after the file grow to 1k, do you have any idea? Is it because of it just only 1K? Please let me know if the below syntax is in correct. # more trotate /sourcepath/*/servers/*/logs/*log... (2 Replies)
Discussion started by: lpprasad321
2 Replies

4. HP-UX

How To Rotate A File in HP-UX?

I need to rotate a file in HP-UX of a application. I´ve tried to do a task in the cron with a script (with sed and ed commands) but it was a successfully option (the application continued writing the file :( ) LINEAS_OUT=$(wc -l < $RMISTDOUT) LINEAS_FIN=1,expr $LINEAS_OUT - 100p sed... (19 Replies)
Discussion started by: werkraft
19 Replies

5. Programming

Badly places ()'s on C

I dont know why this Linux would give me badly placed () error all the time for this; #include <stdio.h> int main() { register int num=0 ; while ((num < 5)) ++num; printf("Pass %d \n", num) ; return 0 ; } can anyone help me please? (11 Replies)
Discussion started by: sizzler786
11 Replies

6. Shell Programming and Scripting

Decimal places

i need to multiplay a number with 1.00.. so that the output should contain two decimal places at end.. for example... 236 * 1.00 = 236.00 245.8 * 1.00 = 245.80 but when i perform multiplication it shows output as. 236 245.8 can anyone help me to get the actual output of... (11 Replies)
Discussion started by: arunmanas
11 Replies

7. Programming

Rotate an array

i have an array a={1,2,3,4,5} the output should be a= {4,5,1,2,3} please help me writin this program in c. (10 Replies)
Discussion started by: pgmfourms
10 Replies

8. UNIX for Advanced & Expert Users

log rotate

hi , what is the meaning of log rotate? how do i rotate /var/adm/wtmps log and gzip it? (6 Replies)
Discussion started by: cromohawk
6 Replies

9. UNIX for Dummies Questions & Answers

deciaml places

Hello All, Can anyone please tell me how do i define the variable as decimal. Below is my script. After division i get a whole number where as i want to see the decimal places also.. TABLEAVG=`expr ${TABLECHARS}/${TABLELINES} | bc` EG: if TABLECHARS= 1280 and TABLELINES=44 the O/P is... (6 Replies)
Discussion started by: OSD
6 Replies

10. UNIX for Advanced & Expert Users

HP-UX lp spooling places

Does anybody know if HP-UX uses any other directories besides /var/spool/lp/request to spool print jobs? I checked the man pages, and it only mentions /var/spool/lp in general. I was just wondering if anyone knew of some other place it might possibly use. thanks in advance for any help! (2 Replies)
Discussion started by: doeboy
2 Replies
Login or Register to Ask a Question