0% found this document useful (0 votes)
11 views

Computer

Computer Project

Uploaded by

batmanop005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Computer

Computer Project

Uploaded by

batmanop005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Computer Science Project |1

COMPUTER
SCIENCE PROJECT

NAME – Shoaib Qureshi


CLASS – XII-D
ROLL NO. - 15
SESSION – [2023-2024]

Shoaib Qureshi
Computer Science Project |2

Program 1)WAP in java to calculate area


and perimeter of triangle.

Step 1 – Start.
Step2 –Get the length of sides inputted by the user.
Step3 – Calculate perimeter by adding lengths of
all the sides.
Step4- Calculate area by formula(√[s × (s – a) ×
(s – b) × (s – c)]) where s=(l1+l2+l3)/2).
Step5-Stop.

Shoaib Qureshi
Computer Science Project |3

Program –

class Program1
{
void main(int l1, int l2, int l3)
{
int s=(l1+l2+l3)/2;
int P = 2*s;
int area = (int)Math.sqrt(s*(s-l1)*(s-l2)*(s-l3));
System.out.println("first side is" +l1);
System.out.println("second side is "+l2);
System.out.println("third side is "+l3);
System.out.println("area is "+area);
System.out.println("perimeter is "+P);
}
}

Shoaib Qureshi
Computer Science Project |4

Output-
Input
l1=5 l2=4 l3=3
Output
first side is 3
second side is 4
third side is 5
area is 6
perimeter is 12

I1 int First side of


triangle.
I2 int Second side of
triangle.
I3 int Third side of
triangle.
perimeter int Perimeter of
triangle.
area int Area of
triangle.

Shoaib Qureshi
Computer Science Project |5

Program 2)Write a program in java to


search a digit in a number by using
recursion.

Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return false when the value of n is zero as
base case.
Step4 – Call the function to go for another round
without a loop and keep checking for equality.
Step5 – Stop.

Shoaib Qureshi
Computer Science Project |6

Program-
class Program2
{
boolean search(int N,int x)
{
if(N==0)
return false;
else
{
int d = N%10;
if(d==x)
{
return true;
}
else
{
return search(N/10,x);
}

Shoaib Qureshi
Computer Science Project |7

}
}}
Output-
Input
N=720
X=2
Output
True

VARIABLE DATATYPE DESCRIPTIO


N
N int To input value
of number.
d int To extract each
digit of the
number.
X int Digit to be
searched.

Shoaib Qureshi
Computer Science Project |8

Program 3)Enter any number and check


if its neon or not.

Step 1 – Start.
Step2 –Get number inputted by user.
Step3 – Calculate sum of digit.
Step4 -Check whether sum is equal to 9 or not and
print neon if it is else print not a neon number.
Step5-Stop.

Program –
Shoaib Qureshi
Computer Science Project |9

class Program3
{
public static void main(int N)
{
int s = 0;
while(N>0)
{
int d=N%10;
s=s+d;
N=N/10;
}
if(s==9)
System.out.println("Neon");
else
System.out.println("Not Neon");
}
}
Output-

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 10

Input
N=324
Output
Neon

VARIABLE DATATYPE DESCRIPTIO


N
N int Number
inputted by
user.
d int To get each
digit of the
number.
s int To get the sum
of digit.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 11

Program 4)WAP in java to check if


number is Niven or not.(Niven number
is divisible by sum of its digits).

Step 1 – Start.
Step2 –Get the number inputted by the user.
Step3 – Make a copy of number.
Step4- Calculate the sum of digit by a while loop.
Step5-Now check if the copy of number is divisible
by sum of digit or not if it is then print Niven else it
is not Niven.
Step6-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 12

Program-
class Program4
{
void main(int N)
{
int s=0, M=N;
while(N>0)
{
int d=N%10;
s=s+d;
N=N/10;
}
if(M%s==0)
System.out.println("Niven Number");
else
System.out.println("Not a Niven Number");
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 13

Output-
Input
N=126
Output
Niven Number

VARIABLE DATATY DESCRIPTION


PE
N integer Number inputted by
user.
M integer Copy of number N.
s integer To store sum of digits
of the number.
d integer To extract each digit
of number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 14

Program 5)Write a program in java to


add n natural numbers by using
recursion.

Step 1 – Start.
Step2 – Form a function for sum and get the value
of n inputed by the user.
Step3 – Return 1 when the value of n is one as base
case.
Step4 – Call the function to go for another round
without a loop.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 15

Program-
class Program5
{
int sum(int N)
{
if(N==1)
return 1;
else
{
return N+sum(N-1);
}
}}
Output-
Input
N=6
Output
21

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 16

VARIABLE DATATYPE DESCRIPTIO


N
N Int To give values
of natural
numbers.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 17

Program 6)Write a program in java to


return the n th term of fibonacci series
by using recursion.

Step 1 – Start.
Step2 – Form a function for finding fibonaci term.
Step3 – If N is one return 0 as base case and if N is
2 return 1 as base case.
Step4 – Call the function to go for another round
without a loop and keep checking for fibonacci
term.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 18

Program-
class Program6
{
int Fibo(int N)
{
if(N==1)
{
return 0;
}
else if(N==2)
{
return 1;
}
else
{
return Fibo(N-1)+Fibo(N-2);
}
}}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 19

Output-
Input
N=4
Output
2

VARIABLE DATATYPE DESCRIPTIO


N
N int To input term
number

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 20

Program 7)Write a program in java to


return number of digits of a number by
using recursion.

Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop and keep adding 1.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 21

Program-
class Program7
{
int countdigit(int N)
{
if(N==0)
return 0;
else
{
int d = N%10;
return 1+countdigit(N/10);
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 22

Output-
Input
N=720
Output
3

Variable Datatype Description


N int To input value
of number.
d int To extract each
digit of the
number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 23

Program 8)WAP in java to print all the


triangular numbers till n.(Number is
sum of consecutive numbers).

Step 1 – Start.
Step2 –Get the number inputted by the user.
Step3 – Check if the number is greater than 3 or not.
Step4- Make a loop from 3 to n.
Step5-Print sum of all consecutive numbers in
between.
Step6-Stop.

Program-
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 24

class Program8
{
void main(int n)
{
if (n < 3)
{
System.out.println("triangular number are
greater than n");
}

System.out.println("Triangular Numbers from


3 to " + n + ":");
int sum = 3;
for (int i = 3; sum <= n; i++)
{
System.out.println(sum);
sum += i;
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 25

}
Output-
Input
N=7
Output
Triangular Numbers from 3 to 7:
3
6

Variable Datatype Description


N int Number
inputted by
user.
i int Loop variable
from 3 to N.
sum int Storing each
sum.
Program 9)Write a program in java to
last Digit check the number is
palindrome or not.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 26

Step 1 – Start.
Step2 – Form a while loop reverse the number after
making a copy of it.
Step3 – Check the equality of reverse number with
original number.
Step4 - If equal print palindrome else print not
palindrome.
Step5 – Stop.

Program-
class Program9
{

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 27

void main(int N)
{
int R=0;
int t = N;
while(t>0)
{
int d = t%10;
R = R*10+d;
t=t/10;
}
if(N == R)
System.out.println(N+ "is a Palindrome no");
else
System.out.println(N+ "is not a Palindrome
no"); } }
Output-
Input
N=525
Output
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 28

525 is a palindrome
number.

Variable Datatype Description


N int To input
decimal
number.
R int To store reverse
of the number.
d int To get each
digit of number
one by one.
t int To get the copy
of number.

Program 10)WAP in java to check if


number is pronic or not.(Pronic number
is product of consecutive numbers).

Step 1 – Start.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 29

Step2 –Get the number inputted by the user.


Step3 – Make a loop from 1 to n-1.
Step4- Check equality of number with each
consecutive product if it is equal make flag 1.
Step5-If flag is 1 then print pronic else print not
pronic.
Step6-Stop.

Program-
class Program10
{
void main(int n)
{
int F=0;
for(int i=1;i<=n-1;i++)
{
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 30

if(i*(i+1)==n)
F=1;
}
if(F==1)
System.out.println("Pronic");
else
System.out.println("Not Pronic");
}
}

Output –
Input
N=6
Output
Pronic Number

Variable Datatype Description


N int Number
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 31

inputted by
user
i int Loop variable
from 1 to N-1.
F int Flag to check
for
confirmation of
equality.

Program 11)WAP in java to check if the


number entered is an evil number or not.

Step 1 – Start.
Step2 –Get the number inputted by the user.
Step3 – Convert the number from decimal to binary.
Step4- Count the number f 1’s in the binary number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 32

Step5-If the number of 1’s is even the number is


evil else it is not an evil number.
Step6-Stop.

Program –
class Program11
{
void main(int n)
{
int c=0,p=0,bin=0;
while (n > 0)
{
int d = n % 2;
if (d == 1)
c++;

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 33

bin += (int)(d * Math.pow(10, p));


p++;
n /= 2;
}
if(c%2==0)
System.out.println("Evil Number");
else
System.out.println("Not an Evil Number");
}
}

Output –
Input
N=14
Output
Not an Evil Number

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 34

Variable Datatype Description


N int Number
inputted by
user.
c int Counting the
number of 1’s
in binary
form.
d int Getting each
digit of the
number.
p int Used for
conversion of
decimal no. to
binary.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 35

bin int To store


binary form of
number.

Program 12)WAP in java to calculate


area and circumference of circle.

Step 1 – Start.
Step2 –Get the radius of circle inputted by the user.
Step3 – Calculate area by formula(A=2*3.14*r*r).
Step4- Calculate circumference by
formula(C=(2*3.14*r)).
Step5-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 36

Program –
class Program12
{
void main(double r)
{
double area = 3.14*r*r;
double circumference = 2*3.14*r;
System.out.println("Radius is "+r);
System.out.println("Area is "+area);
System.out.println("Circumference is
"+circumference);
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 37

Output –
Input
radius=5
Output
Radius is 5.0
Area is 78.5
Circumference is 31.40

Variable Datatype Description


radius double Radius of
circle.
circumference double Circumference
of circle
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 38

area double Area of circle

Program 13)WAP in java to calculate


volume and surface area of cylinder.

Step 1 – Start.
Step2 –Get the radius and height of cylinder
inputted by the user.
Step3 – Calculate volume by
formula(V=2*3.14*r*r*h).
Step4- Calculate surface area by
formula(SA=(2*3.14*r*r)+(2*3.14*r*h)).
Step5-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 39

Program –
class Program13
{
void main(int radius, int height)
{
double volume = 3.14*radius*radius*height;
double area =
(2*3.14*radius*height)+(2*3.14*radius*radius);
System.out.println("radius is" +radius);
System.out.println("height is "+height);
System.out.println("volume is "+volume);
System.out.println("area is "+area);
}}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 40

Output-
Input
radius=5
height=10
Output
radius is 5
height is 10
volume is 785.0
area is 471.0

Variable Datatype Description


radius int Radius of a
cylinder
height int Height of a
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 41

cylinder
volume int Volume of a
cylinder
area int Area of a
cylinder
Program 14)WAP in java to calculate
area and perimeter of square or
rectangle.

Step 1 – Start.
Step2 –Get the length and breadth inputted by the
user.
Step3 – Calculate area by formula
(A=length*breadth).
Step4- Calculate perimeter by formula
(P=2*(length+breadth)).
Step5-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 42

Program –
class Program14
{
void main(int length, int breadth)
{
int area = length*breadth;
int perimeter = 2*(length+breadth);
System.out.println("length is" +length);
System.out.println("breadth is "+breadth);
System.out.println("area is "+area);
System.out.println("perimeter is "+perimeter);
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 43

Output –
Input
length=5
breadth=6
Output
length is 5
breadth is 6
area is 30
perimeter is 22

Variable Datatype Decription


length int For taking
length
breadth int For taking
breadth
area int For taking area
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 44

perimeter int For taking


perimeter

Program 15)WAP in java to calculate


the simple interest when principal, rate
and time are given.

Step 1 – Start.
Step2 –Get the principal, rate and time inputted by
the user.
Step3 – Calculate simple interest by formula (SI
=(P*R*T)/100).
Step4-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 45

Program –
class Program15
{
void main(double p, double r, double t)
{
double SI=(p*r*t)/100.0;
System.out.println("Principal is "+p);
System.out.println("Rate is "+r);
System.out.println("Time is "+t);
System.out.println("Simple Interest is "+SI);
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 46

Output –
Input
P=10,000
R=15%
T=5 years
Output
Principal is 10000.0
Rate is 15.0
Time is 5.0
Simple Interest is 7500.0

Variable Datatype Description


p double For principal
r double For rate
t double For time
si double For calculating
simple interest
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 47

Program 16)Enter any word and print


pair of characters.

Step 1 – Start.
Step2 –Get the length of word inputted.
Step3 – Make a loop from starting to the second
last character.
Step4 -Get the characters and print them
simultaneously.
Step5-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 48

Program –
class Program16
{
public static void main(String nm)
{
int l = nm.length();
for(int i=0;i<=l-2;i++)
{
char d = nm.charAt(i);
char e = nm.charAt(i+1);
System.out.println(d+" "+e);
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 49

Output –
Input
nm=“Rajesh”
Output
Ra
aj
je
es
sh

Variable Datatype Description


nm string Word inputted by
user.
l int To count the
number of
characters in
string.
d char To get the first
character one by
one.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 50

e char To get the second


character one by
one.
Program 17)Write a program in java to
last Digit check the number is
fascinating or not.
Step 1 – Start.
Step2 – First, check the given number consist of
three digits or not. If no, print cannot be a
fascinating number.
Step3 – Now, multiply the given number by 2 and 3,
separately.
Step4 - Convert the results (from step 2) into a
string.
Step5 – Concatenate the strings (from step 3) with
the given number (n).
Iterate over the string that we get after
concatenation and count the frequency of each digit.
Step6- Print "not a fascinating number" if any digit
is missing or appeared multiple times. Else, print
"fascinating number".

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 51

Step7-Stop
Program –
class Program17
{
public static void main(int N)
{
int n2 = N * 2;
int n3 = N * 3;
String concatstr=N + "" + n2 + n3;
boolean found = true;
for(char c = '1'; c <= '9'; c++)
{
int count = 0;
for(int i = 0; i < concatstr.length(); i++)
{
char ch = concatstr.charAt(i);
if(ch == c)
count++;

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 52

}
if(count > 1 || count == 0)
{
found = false;
break;
}
}
if(found)
System.out.println(N + " is a fascinating
number.");
else
System.out.println(N + " is not a fascinating
number.");
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 53

Output –
Input
N=327
Output
525 is a fascinating
number.

Variable Datatype Description


N int To input a
number
N1 int To store the
value
N2 int To store the
value
ch char Loop variable
to check the no.
of numbers.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 54

Program 18)Create a function isprime to


check for prime and return true or false.

Step 1 – Start.
Step2 – Make a loop from 1 to that number.
Step3 – Check the divisibility of number with each
number in the loop and count the divisibility
condition to be zero.
Step4 -Check that counter is 2 or not and print true
or false according to it.
Step5-Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 55

Program –
class Program18
{
boolean isprime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 56

Output –
Input
N=13
Output
True

Variable Datatype Description


N int To input a
number
c int Counter for
counting the
number of
conditions.
i int Loop variable
to give values
for division for
checking
prime.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 57

Program 19)Write a program in java to


return factorial of n natural numbers by
using recursion.

Step 1 – Start.
Step2 – Form a function for factorial and get the
value of n inputed by the user.
Step3 – Return 1 when the value of n is one as base
case.
Step4 – Call the function to go for another round
without a loop.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 58

Program –
class Program19
{
int Fact(int N)
{
if(N==1)
return 1;
else
{
return N*Fact(N-1);
}
}
}
Output –
Input
N=6
Output
720

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 59

Variable Datatype Description


N int To give values
of natural
numbers.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 60

Program 20)Write a program in java to


return digit of a number by using
recursion.

Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputted by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 61

Program –
class Program20
{
void extract(int N)
{
if(N==0)
return;
else
{
int d = N%10;
System.out.println(d);
extract(N/10);
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 62

Output –
Input
N=720
Output
0
2
7

Variable Datatype Description


N int To input value
of a number
d int To extract each
digit of the
number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 63

Program 21)Write a program in java to


return sum of digit of a number by using
recursion.

Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop and keep adding the digit.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 64

Program –
class Program21
{
int sumdigit(int N)
{
if(N==0)
return 0;
else
{
int d = N%10;
return d+sumdigit(N/10);
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 65

Output –
Input
N=720
Output
9

Variable Datatype Description


N int To input value
of a number
d int To extract each
digit of the
number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 66

Program 22)Write a program in java to


return product of digits of a number by
using recursion.

Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop and keep multiplying the digits.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 67

Program –
class Program22
{
int productdigit(int N)
{
if(N==0)
return 1;
else
{
int d = N%10;
return d*productdigit(N/10);
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 68

Output –
Input
N=720
Output
3

Variable Datatype Description


N int To input value
of a number
d int To extract each
digit of the
number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 69

Program 23)Write a program in java to


return the HCF of two numbers by using
recursion.

Step 1 – Start.
Step2 – Form a function for finding hcf by long
division method.
Step3 – If the first number is divisible by another
one return it as base case.
Step4 – Call the function to go for another round
without a loop and keep checking for divisibility.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 70

Program –
class Program23
{
int HCF(int A,int B)
{
if(B%A==0)
return A;
else
{
int R = B%A;
B=A;
A=R;
return HCF(A,B);
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 71

Output –
Input
A=8
B=12
Output
4

Variable Datatype Description


A int To input value
of first number.
B int To input value
of second
number.
R int To calculate
remainder of
their division.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 72

Program 24)Write a program in java to


return the binary value of a decimal
number by using recursion.

Step 1 – Start.
Step2 – Form a function for converting decimal to
binary.
Step3 – If N is one return 0 as base case.
Step4 – Call the function to go for another round
without a loop and keep dividing by 2.
Step5 – Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 73

Program –
class Program24
{
int DecToBin(int N)
{
if(N==0)
{
return 0;
}
else
{
int d = N%2;
return DecToBin(N/2)*10+d;
}
}
}

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 74

Output –
Input
N=4
Output
100

Variable Datatype Description


N int To input
decimal
number.
d int To calculate
remainder
while dividing
by 2.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 75

Program 25)Write a program in java to


Dec Tobin check the number is
automorphic or not.

Step 1 – Start.
Step2 – Form a while loop to count the no. of digits
in the number after making a copy of it.
Step3 – Calculate square of number.
Step4 - Get the last digits of the number and check
for equality with original number .
Step5 – If equal print automorphic else print not
automorphic.
Step6 - Stop.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 76

Program –
class Program25
{
public static void main(int N)
{
int c=0;
int sq = N*N;
int t = N;
while(t>0)
{
c++;
t=t/10;
}
int lastDigit = (int) (sq%(Math.pow(10, c)));
if(N == lastDigit)
System.out.println(N+ "is an automorphic
number");
else

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 77

System.out.println(N+ "is not an


automorphic number");
}
}

Output –

Input
N=25
Output
25 is an automorphic
number.

Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 78

Variable Datatype Description


N int To input
decimal
number
sq int To calculate
square of
number
c int To get the
copy of
number
t int Counter to
count no. of
digits in the
number.

Shoaib Qureshi

You might also like