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:

  • 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+… Read More
  • Application of struct in C#include<stdio.h> #include<string.h> struct student {     char name[20];     int roll; }; void main() {   struct student s[10],t;   int i,n,j;   printf("Enter no. of students : "… Read More
  • Graphics in C#include <windows.h> #include <stdio.h> void SetColorAndBackground(int ForgC, int BackC); void main() {     int f,b;         system("cls");         printf("Enter … Read More
  • Check if a no. is prime or not in C ?#include<stdio.h> int testprime(int ,int); void main() {     int n,prime;     printf("Enter a positive number : ");     scanf("%d",&n);     prime=testprime(n,n/2);   &nbs… Read More
  • Check if a string is palindrome or not in C ?#include<stdio.h> #include<string.h> void main() {     char word[50];     int i,j,l,c=0;     printf("Enter a word : ");     gets(word);     l=strlen(word);   … Read More

0 comments:

Post a Comment