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

What are the data types present in c?

1147


Why do we use c for the speed of light?

1169


What is the difference between pure virtual function and virtual function?

1106


What is an lvalue?

1052


What is an lvalue in c?

1111


How will you delete a node in DLL?

1275


What is pointer and structure in c?

1145


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

1970


What is the difference between volatile and const volatile?

976


Why is c called c not d or e?

1082


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

1085


a number whose only prime factors are 2,3,5, and 7 is call humble number,,write a program to find and display the nth element in this sequence.. sample input : 2,3,4,11,12,13, and 100.. sample output : the 2nd humble number is 2,the 3rd humble number is 3,the 4th humble number is ,the 11th humble number is 12, the 12th humble number is 14, the 13th humble number is 15, the 100th humble number is 450.

5050


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

2136


What is external variable in c?

1049


What is structure in c explain with example?

1144