check whether a character is vowel or consonant

Q21. Write a code to check whether a character is vowel or consonant

Vowel :- In English, five alphabets A, E, I, O, and U are called as Vowels.
Consonant :- In English, all alphabets other than vowels are Consonant.
For Example :-
Input = E
Output = E is Vowel.
So as we can see that E is alphabets which is Vowel. So, the output is “E is Vowel”.

check whether a character is vowel or consonant Algorithm 

START
Step 1 – Input the alphabets.
Step 2 – Check if the alphabets is (a, e, i, o, u) if alphabet is among these then it is vowel.
Step 3 – If the alphabets is vowel than print Vowel otherwise print Consonant.
STOP

check whether a character is vowel or consonant code

Output

M is a consonant.

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number

Write a code to check armstrong number

Q20. Write a code to check armstrong number

Armstrong Number :- A Armstrong Number is a number that is equal to sum of cubes of each digits.
For Example :- 370
So as we can see that the sum of cubes of each digit (3^3=27, 7^3=343, 0^3=0 => 27+343+0=370) is equal to it’s number. So 370 is an Armstrong number.

Algorithm for Armstrong Number

START
step 1 : read number
step 2 : set sum=0 and duplicate=number
step 3 : reminder=number%10
step 4 : sum=sum+(reminder*reminder*reminder)
step 5 : number=number/10
step 6 : repeat steps 4 to 6 until number > 0
step 7 : if sum = duplicate
step 8 : display number is armstrong
step 9 : else
step 10 : display number is not armstrong
STOP

Code  for Armstrong Number

Output

The number 370 is an Armstrong number.

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number

print all distinct elements of a given integer array

Q19. Write a code to print all distinct elements of a given integer array

Distinct Element :- Distinct elements are nothing but the unique (non-duplicate) elements present in the given array.

Algorithm Distinct Elements In An Array

//Algorithm To Print All Distinct Elements Of A Given Integer Array.
START
Step 1 -> Take array as input arr.
Step 2 -> calculate size of array
Step 3 -> for loop i to n:
for loop j to i:
if arr[i] == arr[j]:
break;
if i == j:
print arr[i]
STOP

Code for Distinct Elements In An Array

Output

5,4,2,8,7,6

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number

Write a code to add two matrices

Q18. Write a code to add two matrices

Solution :In this program, you’ll learn to add two matrices using Nested loop and display it using Nested loop.

Matrices:- A two dimensional(2D) array is known as Matrix. It can have m number of rows and n number of columns where m and n are two integer values.

Algorithm for Matrix Addition

//Algorithm to Add Two Matrices.
START
Step 1 -> Input matrix 1 and matrix 2.
Step 2 -> If the number of rows and number of columns of matrix 1 and matrix 2 are equal then execute step 3 else addition not possible
Step 3 -> for i=1 to rows[matrix 1]
for j=1 to columns [matrix 1]
Input matrix 1 [i,j]
Input matrix 2 [i,j]
matrix 3 [i,j]= matrix 1 [i,j] + matrix 2 [i,j];
step 4-> Display matrix 3 [i,j];
STOP

Code  for Matrix Addition

Output

mat1  mat2
1          2
3          4
5          6
7          8
sum matrix :
3        7
11     15

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number

Write a code to find largest element in an array

Q17.Write a code to find largest element in an array.

Solution :- In this program, we will find the largest/Maximum value element in an array.

For Example :-
input : arr[]={ 2, 5, 3, 6, 4 }
output : 6

So as we can see that the largest element in arr[] = { 2, 5, 3, 6, 4 } is 6 so the output is 6.

Algorithm for Array Largest Number

START
Step 1 → Take an array Arr and define its values
Step 2 → Declare one variable (VAR) and assign 1st element of array to it
Step 3 → Loop for each value of Arr Repeat Step 4
Step 4 → If Arr[I] > VAR, Assign Arr[I] to VAR
Step 5 → After loop finishes, Display VAR which holds the largest element of array
STOP

Code for Array Largest Number

Output

Largest element in an Array is =6

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number