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 |
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 i=10; i=!i>14; Printf ("i=%d",i); }
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }
Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }
main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024
#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }
union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0
main() { int i=5; printf("%d",++i++); }
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
0 Answers Mbarara University of Science and Technology,
What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++<n) p = &arr[i]; *p = 0; }