Showing posts with label palindrome. Show all posts
Showing posts with label palindrome. Show all posts

Sunday, October 30, 2011

String palindrome program in C (without string function )

Write a Program to find whether the Given String is Palindrome or not without using
string functions.


#include<stdio.h>
#include<conio.h>
void main()
{
char s1[20];
int i,j,len=0,flag=0;
clrscr();
printf ("Enter a string:");
gets(s1);for(i=0;s1[i]!='\0';i++)
len++;
i=0;
j=len-1;
while(i<len)
{
if(s1[i]!=s1[j])
{
flag=1;
break;
}
i++;
j--;
}
if(flag==0)
printf("\nstring is palindrome ");
else
printf("\n string is not palindrome");
getch();
}


Read full history - String palindrome program in C (without string function )

Saturday, October 8, 2011

C program to check for Armstrong Number


Write a program in C to check whether the given number is Armstrong or not....



Program...

#include<stdio.h>
#include<conio.h>
void main()
{
int num,r,sum=0,temp;
clrscr();
printf("\nEnter a number:");
scanf("%d",&num);
temp=num;
while(num)
{
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(temp==sum)
printf("\n%d is an armstrong number",temp);
else
printf("\n%d is not an armstrong number",temp);
getch();
}


Output...

Read full history - C program to check for Armstrong Number

C Program to check for Palindrome Number

Write a program to check whether the given number is palindrome or not....



Program


#include<stdio.h>
#include<conio.h>
void main()
{
int num,r,sum=0,temp;
clrscr();
printf("\nEnter a number:");
scanf("%d",&num);
temp=num;
while(num)
{
r=num%10;
num=num/10;
sum=(sum*10)+r;
}
if(temp==sum)
printf("\n%d is a palindrome",temp);
else
printf("\n%d is not a palindrome",temp);
getch();
}


Output...

Read full history - C Program to check for Palindrome Number

About Me