Composite
Composite
/**
Write a program to display all the magic composite numbers from 1 to 100.
A magic composite number is a composite number which gives 1 after repeated addition of the digits of
the sum of digits.
Eg : 64 is a magic composite number. Since 6+4=10 and 1+0=1
**/
ALGORITHM
Step 1: Start
a←i
s←i
c←0
End of j loop
while s>9
n←s
s←0
while n>0
d←n%10
s←s+d
n←n/10
End of i loop
Step 6 : Stop
CODING
import java.util.*;
class MagiCompNumber
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a,n,s,d,i,j,c;
System.out.println("The composite magic numbers from 1 to 100 are :");
for(i=1;i<=100;i++)
{
a=i;
s=i;
c=0;
for(j=1;j<=a;j++)
{
if(a%j==0)
c++;
}//ending of inner loop
while (s>9)
{
n=s;
s=0;
while(n>0)
{
d=n%10;//extracting the digits.
s=s+d;
n=n/10;
}//ending of while loop
}
if (s==1&&c!=2)
System.out.println(a);//printing the magic composite number.
}
}
}
VARIABLE DESCRIPTION
SL VARIABLE DATA STORAGE SCOPE DESCRIPTION
NO. NAME TYPE