C Program to Check Whether a Number is Palindrome or Not - Computer Education

This blog about the basic knowledge of computer and all other topics related to it.

computereducation

Sunday 11 February 2018

C Program to Check Whether a Number is Palindrome or Not

C Program to Check Whether a Number is Palindrome or Not in while loop.


In while loop:

   syntax:
    while condition;
{
statement
}
statement-x;

This  looping allows the execution of staement blockfor the specified number of times.
       It checks a condition specified is true then the statement block will be executed.Aftrer execution of statement of statement block the program control automatically return to the begning of the loop and again checks the condition.if that condition is still ture then the statement block will be executed again.if that condition is false then the program control jumps and executes statement block-x.
 The program in 
C Program to Check Whether a Number is Palindrome or Not

c program for palindrome in while loop:


#include<studio.h>
#include<conio.h>
{
clrscr();
int n,num,r,rev=0;
printf ("Enter any number");
scanf ("%d",&n);
while(n>0)
{
r=n%10;
rev=(rev*10)+r;
n=n/10;
}
(rev==num)
printf ("it is a palindromic number");
else
printf ("it is not a palindromic number");
getch();
}

In for loop:

Syntax:

For(initialization; condition;increment/decrement)
{
statement block;
}
statement-x;

This looping allows the execution of staement-block for the specified number of times.
      The diference betwen the while loop and the for loop is that, the number of intraction of the while loopis unknown but the for loop is unknon.

Hene,
  1. In the initializatio,a counter must be specified by a initial value where the count starts.
  2. The counter ca be any name as a,b,c,d,i,j..........
  3. In the condition the counter must be specified by the counter must be specified by the final value with relational operators where the count stop.
  4. The increment or decrement increases or decreases the counter value. 
  #include<studio.h>
  #include<conio.h>
.
  int i,n,r,s=0
  Printf  ("enter a positiv integer");
  scanf ("%d",&n);

   for(i=n  i<=0   i++)

r=i%10;
s=s*10+r;
i=i/10;

}
if(s==n)
{
printf ("It is a palindromic num ber",n);
}
else
{
printf ("It is a palindromic num ber",n);
}
getch()
;
}


Related programs;

1)Input any positive integer and find out it factorial.


  #include<studio.h>
  #include<conio.h>

Void main()
{
clrscr();
int n=1;
unsigned long int fact=1;

Printf ("Enter any positive integer")
Scanf ("%d",n);
While(n>=1)
{
fact=fact*n;
n--;
}
printf ("factorial=",fact);
getch();

}

2)Input any and find out the sum of digits;

  #include<studio.h>
  #include<conio.h>
void main()
{
clrscr();

int n,r,s=0;
printf ("Enter any number")
scanf ("%d",n);
While(n/=0)
{
r=n510;
s=s+r
n=n/10;
}
printf("sum of the digit =",s);

getch();
}

3)Input any number and check wheather it is prime or not:

  #include<studio.h>
  #include<conio.h>
void main()
{
clrscr();
int n, i=1, count=0;
printf ("Enter any number");

scanf ("%d",n)
{
count++;
i++;
}
if(count==2)
{
printf ("it is a prime number");
{
else
}
printf (it is not a prime number")
getch();

}
 if you want more programs then click here"click"

Email id:akashkumarswain14@gmail.com

No comments:

Post a Comment

Thanks for join with us.