[go: up one dir, main page]

0% found this document useful (0 votes)
118 views8 pages

YP ICSE 10th Number Based Programs

The document contains code for 22 programs to analyze numbers based on their digits. It takes a number as input and performs various calculations and checks on the number's digits including: summing and multiplying digits, checking for palindromes, even/odd digit properties, Armstrong numbers, and other number types. The programs are explained with comments and examples are provided for calculating sum/product of digits and partitioning results by even/odd digits.

Uploaded by

divyansh661799
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views8 pages

YP ICSE 10th Number Based Programs

The document contains code for 22 programs to analyze numbers based on their digits. It takes a number as input and performs various calculations and checks on the number's digits including: summing and multiplying digits, checking for palindromes, even/odd digit properties, Armstrong numbers, and other number types. The programs are explained with comments and examples are provided for calculating sum/product of digits and partitioning results by even/odd digits.

Uploaded by

divyansh661799
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points

****************************************************************************************************************************************************************
Master Program of Number programs (Based on number’s digits) (22 Programs)

import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
a = n;
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit

sum = sum + dig ; //Q1→ To get the sum of digits

prod = prod * dig ; //Q2→ To get the product of digits

rev = rev * 10 + dig ;//Q3→Get Reverse number(Palindrome)

cnt++; //Q4→ To get the total number of digits

if( dig%2 == 0 )
{
esum = esum + dig; //Q5→ To get sum of even digits.
eprod = eprod * dig; //Q6→ To get product of even digits.
ecnt++; //Q7→ To get total number of even digits
}
else
{
osum = osum + dig //Q8→ To get the sum of odd digits.
oprod = oprod * dig; //Q9→ To get product of odd digits.
ocnt++; //Q10→ To get total number of odd digits
}
//Q11→ To get sum of cube of digits(Armstrong)
asum = asum + Math.pow( dig, 3);

if( dig > max ) //Q12→ To get maximum digit


max = dig ;

if( dig < min ) //Q13→ To get minimum digit


min = dig ;
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→1
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
//Q14→ To check Super Six number(A Super Six number is number which contains at least two or
more sixes.)
if( dig == 6 )
sscnt++ ;

//Q15→ To check Duck number (A Duck number is number which has zeroes present in it.)
if( dig == 0 )
zcnt++ ;
} // End of while loop

if( asum == a ) //Q11→ To check Armstrong number


System.out.println(“ It is Armstrong Number”);
else
System.out.println(“It is not Armstrong Number”) ;

//Q14→ To check Super six number (A Super Six number is number which contains at least two or
more sixes.)
if( sscnt >= 2 )
System.out.println(“ It is Super six Number”) ;
else
System.out.println(“It is not Super six Number”) ;

//Q15→ To check Duck number (A Duck number is number which has zeroes present in it.)
if( zcnt>0 ) //
System.out.println(“ It is Duck Number”) ;
else
System.out.println(“It is not Duck Number”) ;

//Q16→ To check Niven number (A Niven number is that number which is divisible by its sum of
digits.)
if( a%sum == 0 )
System.out.println(a + " is Niven number");
else
System.out.println(a + " is not Niven number");

//Q17→ To check Spy number (A number is spy number if the sum of its digits equals the product of
its digits.)
if( sum == prod )
System.out.println(“ It is Spy Number”) ;
else
System.out.println(“It is not Spy Number”) ;

//Q18→ To check Special 2-digit Number (A number is a special two-digit number if the sum of its
digits is added to the product of its digits, the result is equal to the original two-digit number.
if( (sum+prod) == a && cnt == 2 )
****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→2
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
System.out.println(“ It is Special 2-digit Number”) ;
else
System.out.println(“It is not Special 2-digit Number”) ;

//Q19→ To check Cyclo number (Cyclo number is the number which has its first and last digit is
same.) int ld = n%10;
if( ld == dig )
System.out.println(a + " is Cyclo number");
else
System.out.println(a + " is not Cyclo number");

//Q20→ To check Micro number (Micro number is the number which has at least one even digit.)
if( cnt > 0 )
System.out.println(a + " is Micro number");
else
System.out.println(a + " is not Micro number");

//Q21→ To check Palindrome number (Q3)


if ( rev == a )
System.out.println(“ it is palindrome number”);
else
System.out.println(“ it is not palindrome number”);

System.out.println(“ Sum of digits = ” + sum);


System.out.println(“ Product of digits = ” + prod);
System.out.println(“ Total no of digits = ” + cnt);
System.out.println(“ Reverse no= ” + rev);
____________
________________
______________

} // End of main()
} // End of class()

****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→3
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q1→ WAP to input a number and find sum of digits and product of digits and total number of digits.
(Q1,2)
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int sum=0, prod=1,cnt=0;
a = n;
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit

sum = sum + dig ; //To get the sum of digits


cnt++;
prod = prod * dig ; // To get the product of digits
}
System.out.printlm(“sum of digits = “+sum);
System.out.printlm(“Product of digits = “+prod);
System.out.println(“Total number of digits = “+cnt);
}
}

****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→4
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q2→ WAP to input a number and find followings. (Q4 to 10)
a) Total number of even digits
b) Total number of odd digits
c) Sum of even digits
d) Sum of odd digits
e) Product of even digit
f) Product of odd digit
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int esum=0, osum=0, eprod=1, oprod=1, ecnt=0, ocnt=0;
a = n;
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
if( dig%2==0 )
{
esum = esum + dig ;
ecnt++;
eprod = eprod * dig ;
}
else
{
osum = osum + dig ;
ocnt++;
oprod = oprod * dig ;
}
}
System.out.printlm(“sum of even digits = “+esum);
System.out.printlm(“Product of evem digits = “+eprod);
System.out.printlm(“sum of odd digits = “+osum);
System.out.printlm(“Product of odd digits = “+oprod);
System.out.printlm(“Total number of even digits = “+ecnt);
System.out.printlm(“Total number of evem digits = “+ocnt);

}
}

****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→5
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q3→ WAP to input a number and find its reverse number and also check it is palindrome or not.
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int rev=0;
a = n; //copy of n number
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit

rev = rev*10 + dig ;

}
System.out.printlm(“reverse number = “ + rev);
if(a==rev)
{
System.out.println(“It is palindrome number”);
}
else
{
System.out.println(“It is not palindrome number”);
}
}

****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→6
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q3→ WAP to input a number and check it is Armstrong number or not.
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int sum=0;
a = n; //copy of n number
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit

sum = sum + dig*dig*dig ; // Math.pow(dig,3)

if(a==sum)
{
System.out.println(“It is Armstrong number”);
}
else
{
System.out.println(“It is not Armstrong number”);
}
}

****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→7
JMD-HGGM YP COMPUTER CLASSES Icse_Key_Points
****************************************************************************************************************************************************************
Q14→ To check Super six number (A Super Six number is number which contains at least two or
more sixes.)
import java.util.Scanner;
public class DigitsOfNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n, dig, a;
System.out.println("Enter a Number ");
n = sc.nextInt();
int cnt=0;
a = n; //copy of n number
while(n != 0) // while(n>0)
{
dig = n%10; // Get the last digit
n = n/10 // Remove last digit
if( dig==6 )
{
cnt++;
}
}

if( cnt >= 2 )


System.out.println(“ It is Super six Number”) ;
else
System.out.println(“It is not Super six Number”) ;

****************************************************************************************************************************************************************
Do More Practice with Me. www.YpComputerClasses.in P→8

You might also like