Saturday, 21 September 2013

SMITH number

import java.io.*;//a java program to check whether the number is a smith number or not
class smith//class name
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,m,d,e,i,j,c,s=0,p=0,l;//variables required
System.out.println("Enter the number to check whether the number is smith or not : -");
n=Integer.parseInt(br.readLine());
m=n;
while(m>0)//the sum of the digit is found out
{
d=m%10;
s=s+d;
m=m/10;
    }
    for(i=1;i<=n;i++)//the for loop is run to find out the prime factors of the number
    {
        c=0;
        if(n%i==0)
        {
            for(j=1;j<=i;j++)//number of factors is calculated
            {
                if(i%j==0)
                {
                    c++;
                }
            }      
                if(c==2)//if there are two factors ,the number is prime
                {
                    l=i;
                    while(l>0)//the sum of the prime factors is found out
                    {
                        e=l%10;
                        p=p+e;
                        l=l/10;
                    }
                    n=n/i;
                    i=1;
                }    
        }
}
    if(s==p)//If the sum of prime factors is equal to the sum of the digits,the number is smith
    {
     System.out.println("The number is smith number");
    }
    else
    {
        System.out.println("The number is  not smith number");
    }
}
    }

Wednesday, 29 May 2013

Nested Prime

import java.io.*;
class Nestedprime
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,c,j;
        System.out.println("Enter the number to check the prime numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            c=0;
            for(j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    c++;
                }
            }
       
            if(c==2)
            {
                System.out.println(i);
           }
        }  
    }
}

Nested Palindrome

import java.io.*;
class NestedPalindrome
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,s;
        System.out.println("Enter the number to check the armstrong numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            m=i;
            s=0;
            while(m>0)
            {
                d=m%10;
                s=s*10+d;
                m=m/10;
            }
          if(s==i)
        {
            System.out.println(i);
        }
    }
    }
}
           
        

Nested Armstrong

import java.io.*;
class NestedArmstrong
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,s;
        System.out.println("Enter the number to check the armstrong numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            m=i;
            s=0;
            while(m>0)
            {
                d=m%10;
                s=s+d*d*d;
                m=m/10;
            }
          if(s==i)
        {
            System.out.println(i);
        }
    }
    }
}