Computer Project
Computer Project
Acknowledgement
ACKNOWLEDGEMENT
.
Page |2
COMPUTER
Computer PROJECT
Project
Name : Vanshika
Chaudhary
Name:
Chaudhary Krish Kapoor
Class : Class:
XI-B XI Sec: B
Index
INDEX
S.No. Program Page No.
P1 Special Factorian Number 4-6
P2 Special Two Digit Number 7-9
P3 Series 10-11
P4 Prime Palindrome Number 12-13
P7 Happy Number 14-16
P8 Emirp Number 17-19
P9 Sum of Composite Numbers 20-21
P10 Magic Number 22-23
P14 Double Dimension Array – 24-26
# Sum of boundary
elements
# Largest number in the array
P15 Friendly Number 27-29
Page |4
P1
Program 1
Answer P1-
import java.util.*;
class CHECK
{
int n;
} // input() closed
void isspecial()
{
int sumoffac= fact(n); // checking whether the sum of factorial of digits of the
number is equal to the number
if(sumoffac==n)
System.out.println(n+" is a Special Factorian number.");
else
Page |6
} //isspecial() closed
void main()
{
CHECK obj= new CHECK();
obj.input();
obj.isspecial(); // not calling the funtion int fact(int X) because it is already called in
funtion void isspecial()
} //main closed
} //class closed
Page |7
Program
P2 2
Answer P2-
import java.util.*;
class Special
{
int m,n;
int cnt;
} //readRange() closed
void countSpecial()
{
cnt=0;
for(int r=m; r<=n; r++)
{
if(checkSpecial(r))
{
cnt++;
System.out.println(r+" is a Special Two-Digit Number.");
}
}
System.out.println("Number of two-digit numbers between range "+m+" to "+n+" is:
"+cnt);
} //countSpecial() closed
void disp()
{
readRange();
System.out.println("Range of Special Two-Digits numbers is "+m+" to "+n);
countSpecial();
} // display() closed
void main()
Page |9
{
Special obj = new Special();
obj.disp(); /* calling only display function because all other functions are called in it. */
} //main closed
} // class closed
P a g e | 10
Program
P3 3
Answer P3-
import java.util.*;
class Series
{
int N; // to store the number of terms
void input() // function to input the number of terms from the user
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number of terms in the series");
N= sc.nextInt();
} //input() closed
return sumofno;
} // sum() closed
double fact(int x)
{
double fac=1.0;
P a g e | 11
return fac;
} // fact() closed
void call()
{
input();
double sumofseries=0.0;
void main()
{
Series obj = new Series();
obj.call(); /* Calling only call() function because other functions are called in it */
} // main closed
} // class closed
P a g e | 12
Program 4
P4 Goto Top
Answer P4-
import java.util.*;
class NUM
{
int low, high;
NUM(int min, int max) // constructor to initialize the data members bu min and max
{
low= min;
high= max;
}
boolean isPrime(int x)
{
int c=0;
if(c!=2)
return false;
else
return true;
} // isPrime() closed
P a g e | 13
int isPalindrome(int x)
{
int d=0, rev=0; int one=1, zero=0;
for(int i=x; i>0; i/=10)
{
d=i%10; // extracting the digits rev= d + (rev*10); // reversing the
number
}
void printPrimePalindrome()
{
System.out.println("Range of numbers: "+low+" to "+high); for(int i= low ; i<=high ;
i++)
{
if( isPrime(i)==true && isPalindrome(i)==1)
{
System.out.println(i+" is a Prime Palindrome number.");
}
}
} // printPrimePalindrome() closed
} // class closed
P a g e | 14
P7
Program 5 Goto Top
Answer P7-
import java.util.*; class Happy
{ int n;
int sum_sq_digits(int x)
{
int d=0, sumofsq=0;
return sumofsq;
} //sum_sq_digits() closed
void ishappy()
{ int i=n;
do
{
i=sum_sq_digits(i);
}while(i>9);
if(i==1)
System.out.println(n+" is a Happy Number.");
else
P a g e | 16
void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number to be checked");
int num=sc.nextInt();
Program
P8 6 Goto Top
Answer P8-
import java.util.*;
class Emirp
{
int n, rev;
Emirp(int nn)
{
n=nn;
rev=0;
}
void isEmirp()
{
int d=0;
for(int i=n; i>0; i/=10)
{
d= i%10 ;
rev = d + (rev*10) ;
}
Program 7
P9 Goto Top
Answer P9-
import java.util.*;
class Find
{
int lim;
Find(int m)
{
lim=m;
}
if(c!=2)
return true;
else
return false;
} // iscomposite() closed
{
int sum=0;
for(int i=1; i<=lim; i++)
{
if(iscomposite(i))
{
sum += i;
}
}
Program 8
P10 Goto Top
Answer P10-
import java.util.*;
class Magic
{
int n;
Magic()
{
n=0;
}
void getnum(int nn) // function to assign parameter value to member variable i.e. n=nn
{
n=nn;
} // getnum() closed
int sumofdigits(int nn) // function that returns the sum of digits of the number received
{
int d=0, sum=0;
for(int i=nn; i>0; i/=10)
{
d=i%10; // digit extraction
sum+=d; // calculating the sum of digits
}
return sum;
P a g e | 23
} // sumofdigits() closed
void ismagic()
{
int i=n;
while(i>9)
{
i=sumofdigits(i);
}
if(i==1)
System.out.println(n+" is a Magic number.");
else
System.out.println(n+" is not a Magic number.");
} // ismagic() closed
void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number to be checked");
int num=sc.nextInt();
Program 9
P14 Goto Top
Answer P14-
import java.util.*;
class DDR
{
int m; // to store number of rows
int n; // to store number of columns
int arr[][];
Scanner sc= new Scanner(System.in);
void sumboundary()
{
int sum=0;
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
if(i==0 || j==0 || i==(m-1) || j==(n-1))
sum+= arr[i][j];
}
}
void maxarray()
{
int max=0;
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
if(arr[i][j]>max)
max=arr[i][j];
}
}
P a g e | 26
void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number of rows");
int ro=sc.nextInt();
System.out.println("Enter the number of columns");
int co=sc.nextInt();
Program 10
P15 Top
A Friendly number is a number the eventual sum of the digits of the
number is equal to 9.
For Example: 675 = 6 +7+5 = 18
18 = 1+ 8 = 9
As the final sum of the digits of the number 675 is 9 so it is a Friendly
number. Some more Friendly numbers can be 9, 18, 54, 243 etc.
Design a class Friendly to check if a given number is a Friendly
number or not. Some of the member functions of the class are given
below.
Class name : Friendly
Data member
Num : to store the number
Member Functions
Friendly ( int n) : to assign value of n to Num
Write the main( ) function to create object for the class and call
functions.
P a g e | 28
Answer P15-
import java.util.*;
class Friendly
{
int Num;
Friendly(int n)
{
Num=n;
}
return sum;
} //sumOfDigits() closed
if(i==9)
return true;
else
return false;
} // isFriendly() closed
void display()
{
if(isFriendly(Num))
void main()
{
Friendly obj= new Friendly(Num);
obj.display(); /* not calling the other functions because they are called in display()
function */
} // main closed
} // class closed
P a g e | 30
THANK YOU