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

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


Please Help Members By Posting Answers For Below Questions

Is void a keyword in c?

927


What is a program?

1188


Explain c preprocessor?

1049


What is the purpose of macro in C language?

1067


Write a code to remove duplicates in a string.

986


What is the use of getch ()?

1039


What are different types of operators?

994


What are the advantages of the functions?

1099


What is structure of c program?

1082


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

1359


How can I find the modification date and time of a file?

1030


Hai what is the different types of versions and their differences

1901


Why is struct padding needed?

1034


Why do we use int main instead of void main in c?

1104


What is putchar() function?

1080