hi all!!,

can somebody help me??

I need to do a program that scan a decimal, transform it to binary and check if it is palindrome or not and print "palidrome" or "not palindrome"....

i can only use functions and cant use arrays or anything else!

can somebody help me???
these week i got really sick and i need to give that in and im blank!!... help!

thanx

there's no binary pattern representation in C, so you have to use another means to represent the binary pattern from the integer value.

If you can't simply have a function that converts the decimal to the binary pattern and stores it in say a string (char array), then you need to use some bitwise operations, such that you make a copy of first, apply bitwise operations to the copy so the reversed is stored, and compare them.

decimal to binary conversion:=>

int no,d;
int ctr=0;
scanf("%d",&no);
while(no>0)
{
no=no/2;
d=no%2;
printf("%d",d);
ctr++;
}

to check whether it is a palindrome apply this logic:=>

int rev=0;
int a;

while(no>0)
{
d=d%10;
no=no/10;
rev=rev*10+d;
a=rev;
}
printf("%d",rev);
if(a==rev) printf("PALINDROME");
else printf("NOT A PALINDROME");

Edited 7 Years Ago by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

there's no binary pattern representation in C, so you have to use another means to represent the binary pattern from the integer value.

If you can't simply have a function that converts the decimal to the binary pattern and stores it in say a string (char array), then you need to use some bitwise operations, such that you make a copy of first, apply bitwise operations to the copy so the reversed is stored, and compare them.

hi!!! thanx for replying!

im not really allow to use array and bitwise, thats the problem!
any other suggestion???

i an begginner to c programming language van u plese help me to dothis?
1multiply two 4*4 integer matrics
2.swap two numbers without using a third variable
3.read details of 10 students(name,roll no:,score)
4sort the student record with score ,and print it

Comments
Read the rules to post in this forum; do not hijack someone else thread.

no bitwise either, u sure? ....

the problem comes to how you can store and maintain the binary number representation upon the two calls to the reverse function then I believe.

because the program tests it itself (with no human checking), you have to apply the same reverse function twice on the binary representation. Once to get the reverse, and another time on the reverse and see if that output equals the original.

The problem with using integers to represent the binary, is that if you flip the binary representation in an integer that contains trailing zeros you will loose data after the flip because integers do not hold leading zeros (this would be avoided using a data structure or bitwise operators).

you could possibly keep track of the number of trailing zeros and then append them on the second call to reverse integer function, but since you're not using the exact same function twice you could argue about the correctness of your implementation of your palindrome check, or maybe that doesn't matter.

Or perhaps you can find another way to represent the pattern that is allowed.

This article has been dead for over six months. Start a new discussion instead.