MidTerm Flowcharts-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Index

Page
S.No. Flowchart Name
No.
1 Sum of Row and Column of Non Square Matrix. 2-3
2 Sum of each Row and Column of Square Matrix. 4
3 2D Array Print Upper Triangular Elements. 5
4 2D Array Print Lower Triangular Elements. 6
5 2D Array Sum of Left Diagonal and Right Diagonal Elements. 7-8
Flowchart to count the number of vowels and consonants in the
6 9
entered string.
Flowchart to check characters of a string whether it is capital case,
7 10
lower case, digit or special symbol.
8 Flowchart to toggle the case of given string. 11
9 Flowchart to find string length using function. 12
10 Flowchart to copy a string using function. 13
11 Flowchart to reverse a string using function. 14
12 Flowchart to compare two strings using function. 15
13 Flowchart to concatenate two strings using function. 16-17
Flowchart to check whether inputted string is Palindrome or not.
14 18-20
(Long Method)
Flowchart to check whether inputted string is Palindrome or not.
15 21-22
(Short Method)
16 Flowchart to capitalized starting letter of each word in given sentence. 23
17 Flowchart to swap two numbers using pointers and function. 24
18 Flowchart to calculate the area of a triangle using call by reference. 25-26
Flowchart to print average of elements of an array using pointer and
19 27
function.
Flowchart to check whether inputted number is Armstrong or not
20 28
using pointer and function.
Flowchart to find maximum and minimum element in array using
21 29
pointer and function
22 Flowchart to sort an array using pointer and function. 30-31
23 Flowchart to reverse an array using pointer and function. 32-33
24 Flowchart to search an element in an array using pointer and function. 34-35
25 Flowchart to copy a string using pointer and function. 36
26 Flowchart to compare two strings using pointer and function. 37-38
27 Flowchart to concatenate two strings using pointer and function. 39
28 Flowchart to reverse a string using pointer and function. 40
2
3
Ques 2: flowchart for finding sum of each column and row for a
square matrix

start A

Read r , c For i=0 to r-1 , Step1

For i = 0 to r-1,step1 Rsum =0 , csum =0

For j=0 to c-1 ,step 1


for j=0 to c-1,step 1

Read arr [ i ] [ j ]
Rsum=Rsum+arr[i][j]

Csum=Csum+arr[j][i]

A Print Rsum,Csum

stop

4
5
6
5. Draw a flowchart to find sum of right diagonal and left diagonal of a matrix

Start

Read r, c

Is F
r == c Print “Not a Square Matrix”
?

RD = 0, LD = 0

for i=0 to r-1, Step 1

for j=0 to c-1, Step 1

Read arr[i][j]

for i=0 to r-1, Step 1

for j=0 to c-1, Step 1

A B C D

7
A B C D

Is T
i==j LD = LD + arr[i][j]
?

Is T
(i+j)==r-1 RD = RD + arr[i][j]
?

Print LD, RD Stop

8
Ques 6: Flowchart to count the number of vowels and consonants in the entered string.

9
Ques 7: Flowchart to check characters of a string whether it is capital case, lower case, digits
or special symbol.

start

read str[]

i=0

false
Is str[i]≠ ‘\0’ stop

true

true
Is str[i]≥'A' and str[i]≤'Z' print "capital letter"

false

true
Is str[i]≥'a' and str[i]≤'z' print "small letter"

false

true
Is str[i]≥'0' and str[i]≤'9' print "digits"

false
print "special
symbol"

i=i+1

10
Ques 8: Flowchart to toggle the case of a given string

start

read str[]

i=0

false
Is str[i]≠ ‘\0’ print str stop

true

true

Is str[i]≥'A' and str[i]≤'Z' str[i]=str[i]+32

false

false
Is str[i]≥'a' and str[i]≤'z'

true

str[i]=str[i]-32

i=i+1

11
QUES 9: FLOWCHART TO FIND STRING LENGTH USING FUNCTION.

Start

Read str[]

len=my_strlen(str)

Print len

Stop

my_strlen(str[])

i=0

Is F
Return i
str[i]≠‘\0’

i=i+1
=

12
QUES 10: FLOWCHART TO COPY A STRING USING FUNCTION.

Start

Read name[]

my-strcpy(copy,name)

Print copy[]

Stop

my-strcpy(copy[],name[])

i =0

Is F
copy[i]=‘\0’
name[i]≠’\0’

T
copy[i]=name[i] return

i=i+1

13
QUES 11: FLOWCHART TO REVERSE A STRING USING FUNCTION.

Start

Read str[]
my_strrev(str[]
)

my_strrev(str)
len=0

Print str[]
Is str[len] F
≠‘\0’
?
Stop

len=len+1

for i=0,j=len-1 to i<j,


Step1(i), Step-1(j)

temp=str[i]
str[i] = str[j]
str[j]=temp

14
Is s1[i]≠’\0’
OR
s2[i]≠’\0’

15
Ques 13: Draw a flowchart to concatenate two string using function
Start

Read S1[ ] , S2[ ]

my_strcat(S1 , S2)

Print S1[ ]

Stop

16
my_strcat( S1 [ ] , S2[])

l=0

F
Is
S1[l]≠’\0’

l=l+1

i=0

F S1[l]=’\0’
Is
S2[i]≠’\0’

T
return

S1[l]=S2[i]

i=i+1
l=l+1

17
Q14. Draw a flowchart to check whether the entered string is palindrome or not?

Start

Read str[]

my_strcpy(temp,str)

my_strrev(str)

c=my_strcmp(str,temp)

Is c==0 f
Print “Not
Palindrome ”

Print “Palindrome”

Stop

my_strcpy(str2[],str1[]

i=0

18
A

Is F
str1[i]! str2[i]=”\0”
=”\0”?

Return
t

str2[i]=str1[i]

i=i+1

my_strcmp(str1[], str2[])

i=0

Is str[i]!=”\0”
f
Or Return 0
str2[i]=”\0”?

Is t
str[i]>str2[i]? Return 1

C B

19
B
C

Is t
str1[i]<str2
Return -1
[i]?

I=I+1

my_strrev(str)

len=0

Is f
str[len]≠
”\0”?

len=len+1 fori=0,j=len-
for i=0, j=len-1 to i<j,
1toi<j,Step1(i),Step
Step 1(i), Step -1(j)

temp=str[i]

str[i]=str[j]

str[j]=temp

Return

20
15. Flowchart to check whether the string is palindrome or not (Method 2)

Start

Read str[]

c = palin(str)

Is
T
c==0 Print “Palindrome”

Print “Not a
Palindrome”

Stop

palin(str[])

n = mystrlen(str)

for i=0 to n/2, Step 1

A B

21
A B

Is
T
str[i] > str[n-i-1] return 1
?

Is
T
str[i] < str[n-i-1] return -1
?

return 0

mystrlen(str[])

i=0

Is F
return i
str[i] ± ‘\0’
?

i=i+1

22
Ques 16. Draw a Flowchart to capitalized starting letter of each word in given
sentence

Cap(Sen[ ])

Start

Read Sen[ ] Is
Sen[0]>=’a’ F
and
Cap(Sen)
Sen [0]<=’z’
?

Print Sen[ ]
T

Sen[0]=Sen[0]-32
Stop

For i=1 to Sen[i]≠‘\0’ ,Step 1

F Is
Sen[i]=’ ’
?

F Is
Sen[i+1]>=’a’ and
Sen[i+1]<=’z’
?

return Sen[i+1]=Sen[i+1]-32

23
QUES 17: FLOWCHART TO SWAP TWO NUMBERS USING POINTER AND FUNCTION

start

Read a , b

Swap ( &a , &b )

Print a , b

stop
Swap ( * p ,* q )

Temp = * p
*p =* q
*q = Temp

Return

24
QUES 18: FLOWCHART TO CALCULATE AREA OF TRIANGLE BY CALL BY REFERENCE

Start

Read a , b , c

ar = 0

area ( a , b , c, &ar )

Print “the area is “, ar

stop

25
area(a,b,c,*ar)

Is (a+b)>c AND
(b+c)>a AND F
Print “Invalid”
(a+c)>b
?

s = (a + b + c) / 2
*ar = sqrt(s*(s-a)*(s-b)*(s-c))

Return

26
Ques 19: Flowchart to print average of elements of an array using pointer.

Start

Read n

Fori=0 to n, Step 1

Read arr[i]

average(*p,n)

avg=average(arr,n) Sum=0

Print”Average is“,avg For i=0 to n-1, Step1

Sum=Sum+*(p+i)
Stop

avg=Sum/n

return avg
27
20. Draw a flowchart to check whether inputted number is Armstrong or not using
pointer and function.

Start

Read n

temp = n

sum = Armstrong(&n)

Is
F
temp==sum Print “Not Armstrong Number”
?

Print “Armstrong Number” Stop

Armstrong(*p)

sum = 0

Is F
return sum
*p ≠ 0

rem = (*p) % 10
sum = sum + rem*rem*rem
*p = (*p) / 10

28
Ques 21: Flowchart to find maximum and minimum element in array
using pointer and function

29
Q22. Draw a flow chart to sort an array using pointer and function?

Start

Read n

For i=0 to n-1, step 1

Read arr[i]

Sort (arr,n)

For i=0 to n-1, step 1

Print arr[i]

Stop

Sort (*p,n)

For i=0 to n-1 , Step 1

For j=0 to n-2-i, Step


1

A
B C
30
A
B C

Is
false
*(p+j)>*(
p+j+1)?

True

Temp=*(p+j)
*(p+j)=*(p+j+1)
*(p+j+1)=Temp

Return

31
Q23. Draw a flow chart to reverse array using pointer and function?

Start

Read n

For i=0 to n-1, Step


1

Read arr[i]

Rev (arr,n)

For i=0 to n-1,


Step 1

Print arr[i]

Stop

Rev (*p,n)

32
A

Temp =0

For i=0 ,j=n-1 to


i<j, step1(i), step-
1(j)

Temp= *(p+i)
*(p+i)=*(p+j)
*(p+j)=Temp

Return

33
Q24. Draw a flowchart to search an element in an array using pointer and function?

Start

Read n

For i=0 to n-1, step


1

Read arr[i]

Read key

P=search(arr, n, key)

Is P<0 False
Print “Element
? found at index ”,p

true

Print “Element Not found “

Stop

34
Search (*p,n,key)

Index =0

For i=0 to n-1, step 1

Is False
*(p+i)==ke
y

ture

Index = I

break

Return Index

35
Ques 25: Flowchart to copy a string using pointer and function

start

read str[]

mystrcpy(str2,str)

print str2[] stop

mystrcpy(*q,*p)

i=0

false
Is *(p+i)≠null *(q+1)=null return

true

*(q+1)=*(p+i)

i=i+1

36
QUES 26: FLOWCHART TO COMPARE TWO STRINGS USING POINTER AND FUNCTION.

start

Read str1[],str2[]

c=mystrcmp(str1,str2)

Is c==0? F
Print “NotEqual”

Print “Equal”

stop

37
mystrcmp(*p,*q)

i=0

IsIs*(p+i)≠‘
*(p+i)≠‘\0’
\0’OR F
OR Return 0
*(q+i)≠‘\0’?

If
Is T
*(p+i)>
*(p+i) > *(q+i) Return 1
*(q+i)
?
?

If
Is
*(p+i)<
*(p+i) < *(q+i) T Return -1
*(q+i)
?

i=i+1

38
Ques 27: String concatenate using pointer and function

Start Mystrcat(*p,*q)

Read s1[ ]
L=0
i=0

Read s2 [ ]

Mystrcat(s1,s2) Is
F
*(p+L)!=
‘\0’

Print s1 ?

Stop L=L+1

Is
F
*(q+i)!=
‘\0’
?
I=i+1
T

*(p+L+i)=*(q+i)

*(p+L+i)=null

return

39
Ques 28: Reverse string using Pointer and function.

Start myStrRev(*p)

l=0
Read S[ ]

myStrRev(S)
Is
false
*(p+l)!=‘\0’
?
Print S[ ]

true

Stop l=l+1

For i=0,j=l-1 to i<=j,step1(i),step-1(j)

Temp=*(p+i)
*(p+i)=*(p+j)
*(p+j)=Temp

return

40

You might also like