0% found this document useful (0 votes)
77 views2 pages

Class 11 Assignment 6 (Prac)

The document defines a Smith number as a composite number whose sum of digits equals the sum of digits of its prime factors. It provides examples of 85, 222, and 999 being respectively a Smith number, Smith number, and not a Smith number. It then asks the reader to write a Java program that takes a number as input and displays whether it is a Smith number or not. The program uses loops to calculate the sum of digits of the input number and sum of digits of its prime factors, then compares the sums to determine if the number is a Smith number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

Class 11 Assignment 6 (Prac)

The document defines a Smith number as a composite number whose sum of digits equals the sum of digits of its prime factors. It provides examples of 85, 222, and 999 being respectively a Smith number, Smith number, and not a Smith number. It then asks the reader to write a Java program that takes a number as input and displays whether it is a Smith number or not. The program uses loops to calculate the sum of digits of the input number and sum of digits of its prime factors, then compares the sums to determine if the number is a Smith number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Class XI A/B/C Computer Practical Questions

Write it in your practical notebook with algorithm and variable description

Question-6. Date- 19/06/2023


A Smith Number is a composite number whose sum of digits is equal to the sum of digits of its
prime factors obtained as a result of prime factorization (excluding 1). The first few such
numbers are 4, 22, 27, 58, 85, 94, 121 ………………..

Examples: 1
Enter a Number : 85
Sum of Digit = 13
Sum of Prime Factor = 13
It is a Smith Number

Examples: 2
Enter a Number : 666
Sum of Digit = 18
Sum of Prime Factor = 18
It is a Smith Number

Examples: 3
Enter a Number : 999
Sum of Digit = 27
Sum of Prime Factor = 19
It is Not a Smith Number

Write a program to input a number and display whether the number is a Smith number or not.
import java.util.*;
class s11q2
{
public static void main()
{
Scanner in=new Scanner(System.in);
int n,r,ds=0,fs=0,i,j;
System.out.print("Enter a number ");
n=in.nextInt();

for(i=n;i!=0;i=i/10)
{
r=i%10;
ds=ds+r;
}
for(i=2;i<=n;i++)
{
if(n%i==0)
{
for(j=i;j!=0;j=j/10)
{
r=j%10;
fs=fs+r;
}
n=n/i;
i--;
}
}

System.out.println("Sum of Digit= "+ds);


System.out.println("Sum of Prime Factors= "+fs);

if(ds==fs)
{
System.out.print("It is a Smith number ");
}
else
{
System.out.print("It is not a Smith number ");
}
}
}

You might also like