Palindrome Number
C Program
1.For Loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,res,old;
printf("Enter a Number:");
scanf("%d",&n);
old=n;
for(res=0;n>0;n=n/10)
{
res = res * 10 + n%10;
}
if(res==old)
printf("IS PALIDROME");
else
printf("NOT PALIDROME");
}
2.While Loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,res;
printf("Enter a Number:");
scanf("%d",&n);
while(n>0)
{
res = res * 10 + n%10;
n=n/10;
}
if(res==old)
printf("IS PALIDROME");
else
printf("NOT PALIDROME");
}
3.Do While Loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,res;
printf("Enter a Number:");
scanf("%d",&n);
do
{
res = res * 10 + n%10;
n=n/10;
}while(n>0);
if(res==old)
printf("IS PALIDROME");
else
printf("NOT PALIDROME");
}
0 Comments:
Post a Comment