Monday, July 31, 2017

Check if 3rd digit of a no. is prime or not in C ?

#include<stdio.h>
int digitcount(int x)
{
    int r,c=0,i=0,y=x;
    while(x!=0)
    {
        r=x%10;
        x=x/10;
        c++;
    }
    while(y!=0)
    {
        r=y%10;
        y=y/10;
        i++;
        if(i==c-2)
        {
            return r;
        }
    }
}
void primecheck(int p)
{
    int count=0,j;
    for(j=1;j<=p;j++)
    {
        if(p%j==0)
        {
            count++;
        }
    }
    if(count==2)
    {
        printf("3rd digit i.e. %d is prime.",p);
    }
    else
    {
        printf("3rd digit i.e. %d is not prime.",p);
    }
}
void main()
{
    int n,digino;
    printf("Enter the number  : ");
    scanf("%d",&n);
    digino=digitcount(n);
    primecheck(digino);
    getch();
}

Related Posts:

  • Find HCF in C#include<stdio.h> int hcf(int a,int b,int c) {     if(a%c==0 && b%c==0)     return c;     hcf(a,b,c-1); } void main() {     int h,x,y;     printf("Enter two numb… Read More
  • Find no. of vowels in a string in C #include<stdio.h> void strcount(char []); void main() {   char str[50];   char c;   while(1)   {     printf("enter string\n");     //gets(str);     scanf("%s",str); &nb… Read More
  • Find highest paid employee in C#include<stdio.h> struct emp {     char name[50];     int salary; }; void main() {     int n,i,sum=0,avg;     struct emp e[20],ls,hs;     printf("Enter the number of emp… Read More
  • Find fibonacci series in C#include<stdio.h> void fibonacci(int); void main() {     int n,first=0,second=1;     printf("Enter the number of fibonacci series to be printed : ");     scanf("%d",&n);     p… Read More
  • Find triangular no. in C#include<stdio.h> void main() {     int n1,n2,i,t;     printf("Enter two numbers : ");     scanf("%d%d",&n1,&n2);     for(i=1;i<=n2;i++)     {     &… Read More

0 comments:

Post a Comment