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 / 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 |
Why do u use # before include in a C Progam?
What are volatile variables?
You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less.
what is c?
What is a pointer in c?
Can a binary search tree be used as an index? If yes, how? Explain
Can we access array using pointer in c language?
can any one tel me wt is the question pattern for NIC exam
Explain what is dynamic data structure?
What is an auto variable in c?
give one ip, find out which contry
What is the scope of static variables in c language?