This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Monday 12 August 2013

Program to check whether the given number and its reverse are same

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int dig(int n, int *a);
revnum(int m, int *a);
int n,m;
void main()
{
int x[10], *a=&x[0], newno;
clrscr();
printf("Enter the number:");
scanf("%d", &n);
m=dig(n, a);
newno=revnum(m,a);
printf("\nReverse of the given number %d= %d",n,newno);
if(n==newno)
printf("\n\nEntered number and reverse number are same");
else
printf("\n\nEntered number and reverse number are not same");
getch();
}
int dig(int n, int *a)
{
int i=0, y;
while(n>0)
{
y=n%10;
*(a+i)=y;
n=n/10;
i++;
}
return i;
}
revnum(int m, int *a)
{
int z=0, s=0, d=m;
for(z=0; z<m; ++z, d--)
s=s+*(a+z)* pow(10, d-1);
return s;
}


No comments:

Post a Comment