The condition expression of the loop is wrong.
for(int k=4;k<0;k--){
You initialized k
with 4 and then are checking whether it is less than 0. As 4 is obviously greater than 0 then the loop will iterate never.
I think you mean the following
for(int k = 4; k >= 0; k-- ) {
But in any case the code looks badly. For example it is not clear what the magic number 5 means and there is no need to use the break stztement.
You could write a function. Here is an example of the corresponding program
#include <stdio.h>
void shift_right( int a[], size_t n )
{
if ( n > 1 )
{
size_t i = n - 1;
int last = a[i];
for ( ; i != 0 ; --i ) a[i] = a[i - 1];
a[i] = last;
}
}
int main(void)
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
const size_t N = sizeof( a ) / sizeof( *a );
size_t i;
for ( i = 0; i < N; i++ ) printf( "%d ", a[i] );
puts( "" );
shift_right( a, N );
for ( i = 0; i < N; i++ ) printf( "%d ", a[i] );
puts( "" );
return 0;
}
The output is
0 1 2 3 4 5 6 7 8 9
9 0 1 2 3 4 5 6 7 8