How to palindrom string in c language?
Answers were Sorted based on User's Feedback
Answer / swati chouksey
1st one of program is for Armstrong number not for
palindrom.......
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / roxy
#include<stdio.h>
#include<string.h>
main()
{
char p1[20], p2[20];
char pal;
clrscr();
printf("Enter a word: ");
gets(p1);
strcpy(p2,p1);
strrev(p1);
if(strcmp(p2,p1)==0)
{
printf("\nIt is a palindrome");
}
else
printf("\nNot a Palindrome");
getch();
}
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / sreejesh1987
#include<stdio.h>
#include<conio.h>
void main()
{
char str[20];
int i,l,n,f=0;
clrscr();
printf("enter string: ");//malayalam
scanf("%s",str);
l=strlen(str)-1;//9-1=8
n=l/2+1;//5
for(i=0;i<n;i++)
if(strcmp(str[i],str[l-i])!=0)//0=m,8-0=m//1=a,8-1=a
f=1;
if(f)
printf("\nNot a palindrome");
else
printf("\nIt is a palindrome");
getch();
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / govind verma
#include<stdio.h>
#include<string.h>
int main()
{
char ch[100];
int len;
printf("enter any string:\n");
gets(ch);
len=strlen(ch);
int i;
int flag=0;
for(i=0;i<=len/2;i++)
{
if(ch[i]==ch[len-1-i])
flag=1;
else
{
flag=0;
break;
}
}
if(flag)
printf("entered string is pallendrom ");
else
printf("entered string is not pallendrom ");
return 0;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
#include<stdio.h>
#include<conio.h>
void main()
{
char n[6];
int i,l;
clrscr();
printf("enter string");
scanf("%s",n);
l=strlen(n);
if((l%2)==0)
exit(0);//length of string is even and cant be a palindrome
for(i=1;i<l/2;i++)
{
if(n[i]==n([l/2+i)])
i++;
else
printf("string is not palindrome");
}
getch();
}
| Is This Answer Correct ? | 3 Yes | 7 No |
Answer / manish kumar
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,b,c;
printf("enter a no.");
scanf("%d",&n);
c=n%10;
n=n/10;
b=n%10;
a=n/10;
if((a*a*a)+(b*b*b)+(c*c*c)==n)
{
printf("entered no. by you is a palindrom no.");
printf("%d",n);
else
printf("enter any button to exit............");
}
getch();
}
| Is This Answer Correct ? | 2 Yes | 11 No |
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }
4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }
int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} iny ccc(){printf(“bye”);} main() { int ( * ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] =ccc; ptr[2](); }
main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5
Finding a number multiplication of 8 with out using arithmetic operator
main() { int i=400,j=300; printf("%d..%d"); }
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }
int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too
C program to print magic square of order n where n > 3 and n is odd