write a function to swap an array a[5] elements like a[0] as
a[5],a[1] as a[4],....a[5] as a[0].without using more than
one loop and use one array not to use temp array?



write a function to swap an array a[5] elements like a[0] as a[5],a[1] as a[4],....a[5] as a[0].wit..

Answer / ashutosh tiwari

void arr_rev(int *arr, int size)
{
int i;
for(i=0;i<(size/2);i++)
{
if(i==size/2)
break;
*(arr+i) = *(arr+i) + *(arr+(size-i-1));
*(arr+(size-i-1)) = *(arr+i) - *(arr+(size-i-1));
*(arr+i) = *(arr+i) - *(arr+(size-i-1));
}
}

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Interview Questions

pointer_variable=(typecasting datatype*)malloc(sizeof(datatype)); This is the syntax for malloc?Please explain this,how it work with an example?

2 Answers   eClerx, Excel, kenexa,


What are directives in c?

0 Answers  


how to make a scientific calculater ?

0 Answers  


Write a program or provide a pseudo code to flip the 2nd bit of the 32 bit number ! (Phone Screen)

1 Answers   NetApp, PTU, Wipro,


What is && in c programming?

0 Answers  






How can you avoid including a header more than once?

0 Answers  


fn f(x) { if(x<=0) return; else f(x-1)+x; }

5 Answers   HCL,


write a program to find the given number is prime or not

2 Answers   Accenture, Vasutech,


Write a C program to fill a rectangle using window scrolling

1 Answers  


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

0 Answers   Celstream,


What is the meaning of typedef struct in c?

0 Answers  


can anyone proide me reading material on svit00ef27@yahoo.com please thanx in advance

1 Answers   IBM,


Categories