I want the logic to write the program based on palindrome.....
Answers
Answered by
0
this program reverse an integer (enters by the users )using while loops .then if statement is used to check whether the reversed number is equal to original no. or not ......an integer is a palindrome if the reverse of that no. is equal to the original no.
pinky137:
Y only while loop
Answered by
0
You can write the program using any Entry controlled Loop.
I am gonna write this program using for loop.Because that is your requirement.
Program for palindrome:
# include<stdio.h>
int main()
{
int a,b,i,d = 0;
printf("Enter a number:");
scanf("%d",&a);
for(i=a;i>0;)
{
b= i%10;
d= d * 10 + b;
i= i/10;
}
if(d == a)
{
printf("Entered number is a palindrome");
}
else
{
printf("Entered number is not a palindrome");
}
return 0;
}
Hope this helps!
I am gonna write this program using for loop.Because that is your requirement.
Program for palindrome:
# include<stdio.h>
int main()
{
int a,b,i,d = 0;
printf("Enter a number:");
scanf("%d",&a);
for(i=a;i>0;)
{
b= i%10;
d= d * 10 + b;
i= i/10;
}
if(d == a)
{
printf("Entered number is a palindrome");
}
else
{
printf("Entered number is not a palindrome");
}
return 0;
}
Hope this helps!
Similar questions