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.[without using the array]
eg:
num=789876
i=2
j=5
778986

Answer Posted / abdur rab

#include <stdio.h>

int get_digits ( int number )
{
int n_digits = 0;
while ( number ) {
n_digits++;
number = number / 10;
}

return ( n_digits );
}

int main ( int argc, char* argv [] )
{
int number = 789876;
int digits = 0;
int temp_number = 0;
int final_number = 0;
int counter = 0;

int start_point = 2;
int end_point = 5;

digits = get_digits ( number );

if ( ( start_point < end_point ) && ( end_point <=
digits ) ) {

temp_number = number;
if ( start_point - 1 ) final_number =
number / pow ( 10, ( digits - ( start_point - 1 ) ) );

counter = digits;
while ( temp_number ) {
if ( ( counter <= ( end_point ) )
&& ( counter >= ( start_point ) ) ) {
final_number *= 10;
final_number += (
temp_number % 10 );
}
temp_number /= 10;
counter--;
}
if ( digits - end_point ) {
final_number *= pow ( 10, ( digits -
end_point ) );
final_number += number % (int) (
pow ( 10, ( digits - end_point ) ) );
}
}

printf ( "\n Number: %d", number );
printf ( "\nFinal Number: %d", final_number );
printf ( "\nS_Pos: %d, E_Pos: %d", start_point,
end_point );

return ( 0 );

}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is better pointer or array?

1021


What are the advantages of union?

1067


How do you define structure?

1041


Explain what happens if you free a pointer twice?

1074


Why C language is a procedural language?

1021


please give me some tips for the placement in the TCS.

2108


how can use subset in c program and give more example

1989


How are 16- and 32-bit numbers stored?

1282


How do you determine the length of a string value that was stored in a variable?

1119


Can a variable be both const and volatile?

1128


Tell us bitwise shift operators?

1091


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

2179


Why we not create function inside function.

2192


How will you find a duplicate number in a array without negating the nos ?

2127


What is the use of typedef in structure in c?

966