Palindrome and armstrong in function C programming

 Palindrome in function :
............................................................................................................
#include<stdio.h>
#include<conio.h>
int palen(int);
int main()
{
int n,p;
printf("Enter number to check palindrome:");
scanf("%d",&n);
p=palen(n);
if(p==n)
printf("%d is palen",p);
else
printf("no palindrome");
getch();
}
int palen(int x)
{
int rev=0, r ;
while(x!=0)
{
r=x%10;
x=x/10;
rev=rev*10+r;
}
return(rev);
}
............................................................................................................
OUTPUT:

 .....................................................................................................

Armstrong in function C programming

......................................................................................................
#include<stdio.h>
#include<conio.h>
#include<math.h>
int arm(int);
int main()
{
int n,p;
printf("Enter number to check Armstrong:");
scanf("%d",&n);
p=arm(n);
if(p==n)
printf("%d is arm",p);
else
printf("no arm");
getch();
}
int arm(int x)
{
int rev=0, r ;
while(x!=0)
{
r=x%10;
x=x/10;
rev=rev+ pow(r,3);
}
return(rev);
}
   ......................................................................................................
Output:
......................................................................................................

Other C Programming:

1 comment:

Powered by Blogger.