write program for palindrome
Answers were Sorted based on User's Feedback
Answer / mojib khan
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[30],str2[30];
int l;
clrscr();
printf("Enter the string \t");
gets(str1);
strrev(str1);//for reverse string
strcpy(str1,str2);//copy str1 to str2
l=strcmp(str2,str1); //comparing strings it will return 0/1
if(l==0)
{
printf("\nString is Palindrom");
}
else
printf("String is not palindrom");
getch();
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / badsha
#include<iostream.h>
void main()
{
int m=0,n,s=0,r;
cout<<"Enter any number :"<<endl;
cin>>n;
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==s)
{
cout<<"it is palindrom :"<<endl;
}
else
{
cout<<"No is Not palindrom :"<<endl;
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
char a[20],b[20];
printf("enter a string");
scanf("%s",&a);
strcpy(b,a);//copies string a to b
strrev(b);//reverses string b
if(strcmp(a,b)==0)//compares if the original and reverse
strings are same
printf("\n%s is a palindrome",a);
else
printf("\n%s is not a palindrome",a);
return 0;
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / prashant gupta
//Using C# Language
using System;
class Palindrome
{
public void CalculatePalindrome()
{
//int number;
Console.Write("Enter the no to check its
Palindromic property : ");
int number = int.Parse(Console.ReadLine());
int temp = number;
int sum = 0;
while (number > 0)
{
Int32 remainder = number % 10;
number = number / 10;
sum = sum * 10 + remainder;
}
if (sum == temp)
{
Console.WriteLine("The no {0} is
palindrome.", sum);
}
else
{
Console.WriteLine("The no {0} is not a
palindrom no.", sum);
}
}
public static void Main()
{
Palindrome _palindrome = new Palindrome();
_palindrome.CalculatePalindrome();
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / prashant gupta
//in C Language
#include <stdio.h>
#include <conio.h>
int main()
{
int number,temp,remainder,sum=0;
printf("\n\nEnter no: ");
scanf("%d",&number);
temp = number; //Value of temp stores unmodified n value
while(number>0)
{
remainder=number%10; //Gets Last Digit
number/=10; //Truncates Last Digit
sum=sum*10 + remainder; //Builds value of reversed number
}
if (sum==temp)
printf ("\nThe Number Is A Palindrome ");
else
printf ("\nThe Number Is Not A Palindrome ");
getch ();
return 0;
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / amol
#include<stdio.h>
void main()
{
int p,q,r,s=0;
printf("\n Enter the number ::");
scanf("%d",&p);
q=p;
while(p>0)
{
r=p%10;
s=s*10+r;
p=p/10;
}
if(s==q)
{
printf("\n Entered number is palindrome...!!!");
}
else
{
printf("\n Enterde number is NOT a palindrome...!!!");
}
getch();
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / ram srikanth
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char n[50],m[50];
clrscr();
printf("Enter a string");
scanf("%s",n);
strcpy(m,n);
strrev(m);
if (strcpy(n,m)==0) printf("Palindrome");
else printf("not a palindrome");
getch();
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / hillol bhattacharya
#include<stdio.h>
#include<conio.h>
void main()
{
int n,s=0,m,r;
clrscr();
printf("enter any no");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==n)
printf("the no is palindrome");
else
printf("no is not palindrome");
getch();
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rupamrox
#include<stdio.h>
#include<conio.h>
main()
{
int n,m,p,rev;
clrscr();
printf("enter a number: ");
scanf("%d",&n);
p=n;
rev=0;
while(n>0)
{
m=n%10;
rev=rev*10+m;
n=n/10;
}
if(rev==p)
printf("%d is palindrome",p);
else
printf("%d is not palindrome",p);
getch();
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / madhupriya
#include<stdio.h>
#include<conio.h>
void main()
{
int n,s=0,m;
clrscr();
printf("enter any no");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==n)
printf("the no is palindrome");
else
printf("no is not palindrome");
getch();
}
Is This Answer Correct ? | 1 Yes | 1 No |
What are inline functions?
What is endl?
What is a driver program?
Explain deep copy?
What is the C-style character string?
what is the use of templates?
We use library functions in the program, in what form they are provided to the program?
What is the use of c++ programming language in real life?
class A { public: void f(); protected: A() {} A(const A&){} }; Examine the class declaration shown above. Why are the default and copy constructors declared as protected? 1. To ensure that A cannot be created via new by a more derived class 2. To ensure that A cannot be copied 3. To ensure that A cannot be used as a base class except when public inheritance has been used 4. To ensure that A cannot be created/copied outside the inheritance chain 5. To ensure that A cannot be instantiated as a static variable
What is a class definition?
Write a C++ Program to Generate Random Numbers between 0 and 100
List the advantages of inheritance.