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...

Print all the palindrome numbers.If a number is not
palindrome make it one by attaching the reverse to it.
eg:123
output:123321 (or) 12321

Answer Posted / abdur rab

#include <stdio.h>

int reverse_digits ( int number, int* digits )
{
int n_digits = 0;
int rev_number = 0;

while ( number ) {
rev_number *= 10;
rev_number += number % 10;
number /= 10;
n_digits++;
}

*( digits ) = n_digits;
return ( rev_number );
}

int palindrome ( int number, int digits )
{
int flag = 1;

while ( number ) {
if ( ( number % 10 ) != ( number / (int)
pow ( 10, digits - 1 ) ) && ( digits > 1 ) ) {
flag = 0;
break;
}

// removing first and last digits
if ( 1 < ( digits -= 2 ) ) {
number /= 10;
number = number % (int) pow ( 10,
digits );
} else break;
}

return ( flag );
}

int main ( int argc, char* argv [] )
{
int number = 123;
int digits = 0;

int rev_number = 0;

rev_number = reverse_digits ( number, &digits );

if ( !palindrome ( number, digits ) ) {
printf ("\n NOT Palindrome, creating
Palindrome");
/**
* if you need 12321 use digits - 1
* if you need 123321 use digits
*/
number *= (int) pow ( 10, ( digits - 1 ) );
number += rev_number % (int) pow ( 10, (
digits - 1 ) );
}

printf ( "\n The Number: %d", number );

return ( 0 );
}

Is This Answer Correct ?    8 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does nil mean in c?

1181


What should malloc(0) do?

1057


What are near, far and huge pointers?

1012


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

2106


What is the advantage of a random access file?

1128


What is c++ used for today?

1060


What are inbuilt functions in c?

982


a program that can input number of records and can view it again the record

1863


What is the size of a union variable?

999


What are linked lists in c?

1085


 write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare.  You will then tabulate this information in another file.

2154


Array is an lvalue or not?

1066


Is struct oop?

959


Explain what is the difference between a string and an array?

1100


explain what is a newline escape sequence?

1039