[go: up one dir, main page]

0% found this document useful (0 votes)
10 views8 pages

Arrays Strings Demo

The document outlines algorithms for summing elements of an array, validating email addresses, and finding the largest element in a 2D array. It includes flowcharts, pseudo code, and dry runs for each algorithm. The email validation function checks for specific conditions regarding the format of the email address.

Uploaded by

lokesh31052k3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Arrays Strings Demo

The document outlines algorithms for summing elements of an array, validating email addresses, and finding the largest element in a 2D array. It includes flowcharts, pseudo code, and dry runs for each algorithm. The email validation function checks for specific conditions regarding the format of the email address.

Uploaded by

lokesh31052k3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Find the sum of the elements of the array

Flow Chart

Start

numberArray={2,
4,6,8,5}

indexVariable=0,
sum=0

indexVariable<s False

izeof(numberAr
ray)

True

sum = sum + numberArray[indexVariable]

indexVariable++

Print sum

Stop
Pseudo Code

Begin

Declare result

Input numberArray[]

result=addElements(numberArray) //Function Call

Print result

//addElements is the corresponding pseudo code of the flowchart

int addElements(int numberArray[])

int sum=0

for(indexVariable=0;indexVariable<sizeof(numberArray);indexVariable++)

sum=sum+numberArray[indexVariable]

return sum

End

Dry Run
Input Variables Condition Output
numberArray indexVariable numberArray[i sum C1 result
[] ndexVariable] (indexVariable<size
of(numberArray))
{2,4,6,8,5} 0
0 2 (0+2)=2 T
1 4 (2+4)=6 T
2 6 (6+6)=12 T
3 8 (12+8)=20 T
4 5 (20+5)=25 T
5 F 25
Flow Chart 2. Provide definition for EmailValidation to satisfy the below
conditions
Start boolean validateEmail(String email)
{
....
....
}
emailId=”resingto
1) Email id should not start with '.' and '@'
n@gmail.com” 2) Email id should end with either 'm' or 'n'

resultFlag=0,size=
len(emailId)

emailid[0]!=’@ True emailid[size- True


’Or 1]=='m'Or resultFlag=0
emailid[0]!=’.’ emailid[size-
1]==’n’

False False True


resultFlag=2 resultFlag
resultFlag=1
==1
False

Print ” Email ID should


end with m or n”
False
resultFlag
==2

True Print ”Email ID should


not start with @ and .”

return True return False

True
validFlag Print “Email ID
is Valid”

False

Print “Email ID is
Invalid” Stop
Pseudo Code
Begin

Input emailId

validFlag=validateEmail(emailId) // Function Call

if (validFlag)

Print "Email ID is Valid"

else

Print "Email ID is Invalid"

boolean validateEmail(emailId) //Function Definition

resultFlag=0

size=len(emailId)

if emailId[0]!='@' or emailId[0]!='.'

if emailId[size-1]=='m' or emailId[size-1]=='n'

resultFlag=0

else

resultFlag=1

else

resultFlag=2

if resultFlag==1:

print("Email ID should end with m or n")

return False

}
else if resultFlag==2:

print("Email ID should not start with @ and .")

return False

else:

return True

End

Dry Run
Input Variables Condition Output
emailid resultFlag size valid C1 C2 C3 C4 C5 C6 C7
Flag (emailid (emailid (size>10 (resultFl (resultFl (resultFl (validF
[0]!=’@’ [size- and ag==1) ag==2) ag==3) lag)
or 1]=='m' size<20)
emailid[ or
0]!=’.’) emailid[
size-
1]=='n')
diyavin 0 19 T
ay@
T
gmail.c
T
om
True F F F T Email ID
(return is Valid
True)

@rishi 0 15
@gmail 3 F
.com False F F T(return F Email ID
False) is invalid
madhu 0 14 T
@gmail. 2 False F F T(return F Email ID
co False) is
Invalid
3. Find the largest element in a 2D Array

FlowChart
Start

numberArray[2][
2]={{12,5},{3,20}}

rowIndex=0,colIndex=0,

maximum= numberArray[0][0]

False
rowIndex
<2

True

False
colIndex
<2

True

maximum<numberArr
ay[rowIndex][colIndex]

maximum =
colIndex++
numberArray[rowIndex][colIndex]

rowIndex++

Print
maximum

Stop
Pseudo Code

Begin

Declare result

Input numberArray[2][2] = {{12, 5},{ 3 ,20}}

result = maximumElement(numberArray) //Function Call

Print result

//maximumElement is the corresponding pseudocode of the flowchart

int maximumElement(int numberArray[2][2])

Declare maximum, rowindex, colIndex;

maximum = numberArray[0][0]

for(rowIndex=0;rowIndex<2;rowIndex++)

for(colIndex=0;colIndex<2;colIndex++)

if(maximum<numberArray[rowIndex][colIndex])

maximum = numberArray[rowIndex][colIndex]

return maximum;

End
DRY RUN

Input Variables Condition Output


numb maxim rowIndex colIndex numberArr result C1 C2 C3 result
erArr um ay[rowInde rowIndex colIndex Maximum<number
ay[2][ x][colIndex] <2 <2 Array[rowIndex][co
2] lIndex]
{12,5 12 0 0 12 T T F
,3,20
}
1 5 T F
2 F
1 0 3 T T F
1 20 T T
20 2 F
2 F 20

You might also like