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

COMPUTER PROJECT

Uploaded by

14Prabhav Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

COMPUTER PROJECT

Uploaded by

14Prabhav Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

COMPUTER

PROJECT

NAME-PRABHAV GUPTA
CLASS- 11
SECTION- J
ROLL NUMBER- 21
TYPE 1-NUMBER BASED
PROGRAM
PROGRAM 1
Topic:
A binary to decimal conversion
program converts a binary number
(base-2) into its equivalent decimal
number (base-10).
Algorithm:
1. Input a binary number as a string.
2. Initialize a variable decimal to 0.
3. For each digit in the binary
number (from right to left):
o If the digit is '1', update decimal
by adding 2^position (where
position starts from 0).
o Increase the position by 1.
4. Print the resulting decimal
number.
Program:

Output:
Variable Data Table

Variable Type Purpose


binary String Stores the
binary
number input
by the user
decimal Int Holds the
resulting
decimal
number
position Int Tracks the
current
position in
the binary
string (0-
based)
digit char Stores each
character of
the binary
string for
checking
PROGRAM 2
Topic:
A duck number is a positive number
that has zeroes present in it, but
there should be no zero present at
the beginning of the number.
Algorithm:
1. Input a number as a string.
2. Traverse the string, starting
from the second character (to
skip the leading zero).
3. Check if any of the remaining
characters are '0'.
4. If found, the number is a duck
number.
5. If no '0' is found, the number
is not a duck number.
Program:

Output:
Variable Data Table:

Variable Type Purpose


number String Stores the
input
number as
a string
isDuck Boolean Tracks
whether
the
number is
identified
as a Duck
Number
i Int Loop
control
variable to
traverse
the
number
string
TYPE 2-ARRAY 1-D
PROGRAMS
PROGRAM 3
Topic:
This program finds the
largest element in a single-
dimensional array of
integers.
Algorithm:
1. Input the size of the
array.
2. Input the elements of
the array.
3. Initialize a variable
largest with the first
element of the array.
4. Traverse the array:
o If the current element
is larger than largest,
update largest.
5. Print the largest
element found.
Program:
Output:

Variable Data Table:


Variable Type Purpose
Stores the
size int size of the
array
arr Int[]
Array to
store input
elements
Holds the
largest Int largest
element in
the array
Loop control
i Int variable to
traverse the
array
PROGRAM 4
Topic:
This program reverses the
elements of a single-
dimensional array.
Algorithm:
1. Input the size of the
array.
2. Input the elements of
the array.
3. Initialize two pointers:
one at the start (left) and
one at the end (right) of
the array.
4. Swap the elements at
left and right.
5. Move left towards the
middle, and right towards
the middle until they
meet.
6. Print the reversed array.
Program:

Output:
Variable Data Table:
Variable Type Purpose
Stores the
siz Int size of the
e array
Array to
ar Int[] store input
r elements
Points to the
Left Int current left
element
during the
reversal
Points to the
Right Int current right
element
during the
reversal
Temporary
temp int variable to
help swap
elements

TYPE 3-ARRAY 2-D


PROGRAMS
PROGRAM 5
Topic:
This program performs the
addition of two 2D arrays
(matrices).
Algorithm:
1. Input the number of rows
and columns for the matrices.
2. Input the elements of the
first matrix.
3. Input the elements of the
second matrix.
4. Initialize a result matrix of
the same size.
5. Add corresponding
elements of the two matrices
and store them in the result
matrix.
6. Print the result matrix.
Program:
Output:
Variable Data Table:
Variable Type Purpose
Stores the
row Int number of
s rows in the
matrices
Cols Int Stores the
number of
columns in
the matrices
matrix1 Int[][] Stores the
elements of
the first
matrix
matrix2 Int[][] Stores the
elements of
the second
matrix
result Int[][] Stores the
sum of
correspondin
g elements
from the
matrices
Loop control
I,j int variables for
traversing the
2D arrays
PROGRAM 6
Topic:
This program transposes a
given 2D array (matrix) by
converting rows into columns
and vice versa.
Algorithm:
1. Input the number of rows
and columns of the matrix.
2. Input the elements of the
matrix.
3. Initialize a new matrix for
storing the transpose with
swapped rows and columns.
4. For each element at
position [i][j] in the original
matrix, assign it to [j][i] in
the transpose matrix.
5. Print the transposed
matrix.

Program:
Output:
Variable Data Table:
Variable Type Purpose
rows Int Stores the
number of
rows in the
matrix
cols Int Stores the
number of
columns in
the matrix
matrix Int[][] Stores the
elements of
the input
matrix
transp Int[][] Stores the
transposed
ose matrix with
swapped
dimensions
Loop control
i, int variables for
j traversing the
2D arrays
TYPE 4-STRING PROGRAMS
PROGRAM 7
Topic:
This program checks if a given
string is a palindrome (i.e., it reads
the same forwards and backwards).
Algorithm:
1. Input a string.
2. Remove any non-alphabetic
characters and convert the
string to lowercase.
3. Initialize two pointers: one at
the start (left) and one at the
end (right) of the string.
4. Compare the characters at
left and right.
o If they match, move the
pointers towards the middle.
o If they don't match, the string
is not a palindrome.
5. If all characters match, the
string is a palindrome.
Program:

Output:
Variable Data Table:
Variable Type Purpose
Str String Stores the
cleaned,
lowercase
version of
the input
string
Left Int Points to the
current
leftmost
character
Right Int Points to the
current
rightmost
character
isPalindro boolean Tracks whether
me the string is
identified as a
palindrome

PROGRAM 8
Topic:
This program counts the number
of vowels and consonants in a
given string.
Algorithm:
1. Input a string.
2. Convert the string to
lowercase.
3. Initialize two counters:
vowels and consonants.
4. Traverse the string:
o If a character is a vowel (a,
e, i, o, u), increment the
vowels counter.
o If it's an alphabetic
character and not a vowel,
increment the consonants
counter.
5. Print the counts of vowels
and consonants.
Program:
Output:

Variable Data Table:


Variable Type Purpose
str String Stores the
lowercase
version of
the input
string
Vowels in Tracks the
t count of
vowels in the
string
consona Int Tracks the
nts count of
consonants
in the string
i Int Loop control
variable to
traverse the
string
c cha Stores the
current
h r
character
being checked

You might also like