Reverse the part of the number which is present from
position i to j. Print the new number.
eg:
num=789876
i=2
j=5
778986
Answer Posted / abdur rab
#include <stdio.h>
void reverse ( int* ip_array, int st_pos, int ed_pos )
{
if ( ( ip_array ) && ( st_pos < ed_pos ) ) {
* ( ip_array + st_pos ) ^= * ( ip_array +
ed_pos ) ^= * ( ip_array + st_pos ) ^= * ( ip_array +
ed_pos );
reverse ( ip_array, ++st_pos, --ed_pos );
}
}
int main ( int argc, char* argv [] )
{
int int_array [20];
int number = 789876;
int counter = 0;
int nloop = 0;
int start_pos = 2;
int end_pos = 5;
/* split the number into an array */
while ( number ) {
int_array [ counter++ ] = number % 10;
number = number / 10;
}
/* reverse the splited array */
reverse ( int_array, 0, counter - 1 );
/* reverse for the particular position */
if ( ( start_pos < end_pos ) && ( end_pos <=
counter ) ) {
reverse ( int_array, ( start_pos - 1 ), (
end_pos - 1 ) );
number = 0;
for ( nloop = 0; nloop < counter; nloop++ )
{
number *= 10;
number += int_array [ nloop ];
}
printf ( "\n %d", number );
}
return ( 0 );
}
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
how can use subset in c program and give more example
What is a structure member in c?
What are the different types of errors?
What are the usage of pointer in c?
In a header file whether functions are declared or defined?
Explain which function in c can be used to append a string to another string?
Explain what are the advantages and disadvantages of a heap?
How can you tell whether two strings are the same?
Explain indirection?
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
What is the use of getchar functions?
How to throw some light on the b tree?
What language is windows 1.0 written?
Do you know pointer in c?