Beruflich Dokumente
Kultur Dokumente
Subject : Computer Science
Topic: Loops
Worksheet 4
Name……………………………………… Sec………. Date………………..
Q1) WAP to print all the special numbers from 1 till 100. A special number is defined as any two
numbers whose sum of digits and the product of digits when added give the original number.
Q2) WAP to find GCD or HCF and LCM of two numbers.
Greatest Common Divisor (GCD) or Highest Common Factor (HCF) of two positive integers is the
largest positive integer that divides both numbers without remainder. It is useful for reducing
fractions to be in its lowest terms. See below on methods to find GCD.
Lowest Common Multiple (LCM) of two integers is the smallest integer that is a multiple of both
numbers
Q3) WAP to find the sum of all the even and odd numbers within the given range. For example
if the range is 10 and 20
Sum of even numbers= 10+12+14+16+18+20
Sum of odd numbers= 11+13+15+17+19
Q4) WAP to find the sum of squares upto the given number(n). For ex:
N=4
Sum of squares= 1+4+9+16
Q5) WAP to print the following pattern:
For n=4:
1234321
123 321
12 21
1 1
Q6) WAP to find the sum of the following series:
a) S= 7+ 77 + 777+.........n terms
b) S= 1 + x2 + x3 + x4 +............+ xn
Q7) WAP to find whether a number is pal prime or not.
c) A pal prime is a prime number that is also a palindrome number. The first few
decimal palindrome primes are:
a) For n=4:
abcdcba
abc cba
ab ba
a a
ab ba
abc cba
abcdcba
b) For n=3:
1
1 2
1 2 3
Q9. Write the corresponding statement in JAVA for the following expressions using math
function:
a)
b)
c)
Q10) A private company has its employees divided into three grades as per their basic pays as
follows:
Grade I: Basic >= 10000
DA = 40 % of Basic
HRA= 30 % of Basic
Grade II: Basic > 5000 but < 10000
DA = 40 % of Basic
HRA = 30 % Basic
Grade III: Basic < 5000
DA = 20 % of Basic
HRA = 10 % of Basic
Total Salary = Basic + DA+ HRA
Write program to input Basic and Grade and print total salary as per above rules.