Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



Reverse the part of the number which is present from position i to j. Print the new number. eg: n..

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

Post New Answer

More C Interview Questions

can we write a c program with out using main

3 Answers  


9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?

1 Answers  


pgm in c to reverse string by word using array(god is love becomes love is god) (no additional array can used,space is only delimiter between words )

2 Answers   Persistent,


What is the advantage of an array over individual variables?

0 Answers  


what is available in C language but not in C++?

10 Answers   CTS, TCS,


Why c is a mother language?

0 Answers  


What are the uses of pre-processor directives?

2 Answers  


How many header files are in c?

0 Answers  


Explain how do you search data in a data file using random access method?

0 Answers  


What is c++ used for today?

0 Answers  


Can you add pointers together? Why would you?

0 Answers  


What is the Purpose of 'extern' keyword in a function declaration?

0 Answers  


Categories