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

Computer Project

The document is an acknowledgement for a computer project submitted by Vanshika Chaudhary of class XI-B. It thanks the teacher, principal, and parents who supported the project. The index lists 10 programs included in the project on topics like special factorian numbers, prime palindromic numbers, happy numbers, and more. Each program is explained over 2-3 pages with code examples to solve the given problem.

Uploaded by

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

Computer Project

The document is an acknowledgement for a computer project submitted by Vanshika Chaudhary of class XI-B. It thanks the teacher, principal, and parents who supported the project. The index lists 10 programs included in the project on topics like special factorian numbers, prime palindromic numbers, happy numbers, and more. Each program is explained over 2-3 pages with code examples to solve the given problem.

Uploaded by

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

Page |1

Acknowledgement
ACKNOWLEDGEMENT

I would like to express my special thanks of


gratitude to my teacher Mr. Akash Gupta as well as
our Senior Principal Ms. Jyoti Kashyap and
Principal Ms Shivani Singh who gave me the golden
opportunity to do this wonderful Computer project
which also helped me in doing a lot of Research and
I came to know about so many new things I am
really thankful to them.

Secondly I would also like to thank my parents and


friends who helped me a lot in finalizing this project
within the limited time frame.

.
Page |2

COMPUTER
Computer PROJECT
Project
Name : Vanshika
Chaudhary
Name:
Chaudhary Krish Kapoor

Class : Class:
XI-B XI Sec: B

Internal Examiner Sign:


Internal Examiner’s sign:
___________________
External Examiner Sign:
External Examiner’s sign:
____________________
Page |3

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;

CHECK() // constructor to assign value 0 to n


{
n=0;
}

void input() // to accept the value of n


{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number to be checked");
n= sc.nextInt();
Page |5

} // input() closed

int fact(int X) // function to return the factorial of X


{
int dig=0, sum=0;
for(int i=X; i>0; i/=10)
{
dig=i%10; // finding the digits of the number
int factorial=1;
for(int j=1;j<=dig;j++)
{
factorial *= j; // calculating the factorial of the digits
}

sum += factorial; // calculating sum of factorials


}

return sum; // returning the sum of factorial of digits of the number


} // fact() 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

System.out.println(n+" is not a Special Factorian number.");

} //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;

Special() //default constructor


{
System.out.println("Default constructor invoked");
}

void readRange() //function to accept two integers


{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the lower limit of the range");
m=sc.nextInt();
System.out.println("Enter the upper limit of the range");
n=sc.nextInt();
Page |8

} //readRange() closed

boolean checkSpecial(int x) //function to check whether the number is special or not


{
int dig=0,sum=0,pro=1;

for(int i=x; i>0; i/=10)


{
dig=i%10;
sum=dig+sum;
pro=pro*dig;
}
int sumofproandsum= sum+pro;

if(sumofproandsum==x) //checking whether the number is special or not


return true;
else
return false;
} //checkSpecial() 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

double sum(int x) // to calculate the sum of series


{
double sumofno = 0.0;

for(double i=0.0; i<=x; i++)


sumofno += i;

return sumofno;
} // sum() closed

double fact(int x)
{
double fac=1.0;
P a g e | 11

for(double i=1.0; i<=x; i++)


fac *=i;

return fac;
} // fact() closed

void call()
{
input();
double sumofseries=0.0;

for(int i=1; i<=N; i++)


{
sumofseries = sumofseries + (sum(i)/fact(i));
}

System.out.println("Sum of the series is: "+sumofseries);


} // call() closed

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;

for(int i=1; i<=x; i++)


{
if(x%i==0)
c++;
}// checking if the number is prime or not // counting the factors of the
number

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
}

if(rev==x) // checking if the reversed number is equal to the original number


or not
return zero;
else
return one;
} // isPalindrome() closed

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;

Happy() // constructor to assign 0 to n


{
n=0;
}
P a g e | 15

void getnum(int nn) // assigning parameter value to member variable


{
n=nn;
} //getnum() closed

int sum_sq_digits(int x)
{
int d=0, sumofsq=0;

for(int i=x; i>0; i/=10)


{
d=i%10;
sumofsq += (d*d); // calculating the sum of square of digits
}

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

System.out.println(n+" is not a Happy Number.");


} // ishappy() closed

void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number to be checked");
int num=sc.nextInt();

Happy obj= new Happy();


obj.getnum(num);
obj.ishappy();
} // main closed
} // class closed
P a g e | 17

Program
P8 6 Goto Top

Answer P8-

import java.util.*;
class Emirp
{
int n, rev;

Emirp(int nn)
{
n=nn;
rev=0;
}

int isprime(int x) //function to check if a number is prime or not


{
int c=0;
P a g e | 18

for(int i=1; i<=x; i++)


{
if(x%i==0)
{
c++;
}
}
int one=1, zero=0;
if(c==2)
{
return one;
}
else
{
return zero;
}
} // isprime() closed

void isEmirp()
{
int d=0;
for(int i=n; i>0; i/=10)
{
d= i%10 ;
rev = d + (rev*10) ;
}

int num= isprime(n);


P a g e | 19

int numrev= isprime(rev);

if(num==1 && numrev==1)


System.out.println(n+" is an Emirp number.");
else
System.out.println(n+" is not an Emirp number.");
} // isEmirp closed
} //class closed
P a g e | 20

Program 7
P9 Goto Top

Answer P9-
import java.util.*;
class Find
{
int lim;

Find(int m)
{
lim=m;
}

boolean iscomposite(int x) // function to check if the number is composite or not


{ int c=0;
for(int i=1; i<=x; i++)
{
if(x%i==0)
{
c++; // counting the factors
}
}

if(c!=2)
return true;
else
return false;
} // iscomposite() closed

void sumcomposite() // to calculate the sum of composite numbers


P a g e | 21

{
int sum=0;
for(int i=1; i<=lim; i++)
{
if(iscomposite(i))
{
sum += i;
}
}

System.out.println("Sum of composite numbers from 1 to "+lim+" is : "+sum); }


// sumcomposite() closed
} //class closed
P a g e | 22

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();

Magic obj= new Magic();


obj.getnum(num);
obj.ismagic();
} // main closed
} // class closed
P a g e | 24

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);

DDR() // default constructor


{
}

DDR(int mm, int nn)


{
m=mm;
n=nn;
arr= new int[mm][nn];
}

void fillarray() // function to accept elements in matrix


{
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
P a g e | 25

System.out.println("Enter element in matrix at index "+i+","+j+" : ");


arr[i][j]=sc.nextInt();
}
}
System.out.println();
System.out.println("The matrix is:-");
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println();
} //fillarray() closed

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];
}
}

System.out.println("Sum of boundary elements is: "+sum);


} //sumboundary() closed

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

System.out.println("Largest number present in array is: "+max);


} //maxarray() closed

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();

DDR obj = new DDR(ro,co);


obj.fillarray();
obj.sumboundary();
obj.maxarray();
} // main closed
} // class closed
P a g e | 27

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

int sumOfDigits(int nn) : Returns the sum of the digits

boolean isFriendly( int x ) : returns true if the number is


Friendly by calling the function
sumOfDigits(int) otherwise returns false.

void display() : display appropriate message “Number is


a Friendly number” OR “Number is not a
Friendly number” by calling the function
isFriendly(int)

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;
}

int sumOfDigits(int nn) // function to calculate the sum of digits


{
int d=0, sum=0;
for(int i=nn; i>0; i/=10)
{
d=i%10;
sum += d;
}

return sum;
} //sumOfDigits() closed

boolean isFriendly(int x) // function to check whether the number is friendly or not


{
int i=x;
do
{
i= sumOfDigits(i);
}while(i>9);

if(i==9)
return true;
else
return false;
} // isFriendly() closed

void display()
{
if(isFriendly(Num))

System.out.println("Number is a Friendly number.");


else
P a g e | 29

System.out.println("Number is not a Friendly number.");


} // display() closed

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

You might also like