//4. Program to find nth prime and check whether it is palindrome or not.
#include<stdio.h>
void main()
{
int n,i=2,j,k=3,prime,rev=0,rem,temp;
clrscr();
printf("Enter nth number:");
scanf("%d",&n);
printf("2\n");
while(i<=n)
{
for(j=2;j<=k-1;j++)
{
if(k%j==0)
{
break;
}
}
if(j==k)
{
printf("%d\n",k);
i++;
prime=k;
}
k++;
}
temp=prime;
while(temp!=0)
{
rem = temp%10;
rev = rev * 10 + rem;
temp = temp / 10;
}
printf("%dth Prime Number is %d \n",n,prime);
if(prime==rev)
printf("It is Palindrome. \n");
else
printf("It is not Palindrome. \n");
getch();
}
#include<stdio.h>
void main()
{
int n,i=2,j,k=3,prime,rev=0,rem,temp;
clrscr();
printf("Enter nth number:");
scanf("%d",&n);
printf("2\n");
while(i<=n)
{
for(j=2;j<=k-1;j++)
{
if(k%j==0)
{
break;
}
}
if(j==k)
{
printf("%d\n",k);
i++;
prime=k;
}
k++;
}
temp=prime;
while(temp!=0)
{
rem = temp%10;
rev = rev * 10 + rem;
temp = temp / 10;
}
printf("%dth Prime Number is %d \n",n,prime);
if(prime==rev)
printf("It is Palindrome. \n");
else
printf("It is not Palindrome. \n");
getch();
}
No comments :
Post a Comment