Tarun Summer Training
Tarun Summer Training
SUMMER TRAINING
ASSIGNMENT
2
18 Algorithm to Print n Factorial 34
Number
19 Algorithm to add an element in 36
end of an array
20 Algorithm to add an element in 38
Start of an array
21 Algorithm to print an A.P Series 40
22 Algorithm to add an element in 42
middle of an array
23 Algorithm to add an element at an 44
index of an array
24 Algorithm to Print Sum of Two 46
Numbers
3
Flowchart to check voter eligibility:
Step 1 : Start
Step 2 : Take input for users age as a.
Step 3: Check whether a>18 If yes go to step 4 else go to step
5.
Step 4 : Print “Eligible for voting”. Go to step 6
Step 5 : Print ”Not Eligible for Voting”.
Step 6 : Stop.
4
Flowchart to check Even or Odd Number:
Step 1 : Start
Step 2 : Take input for a number from user as a.
Step 3 : Check whether a%2==0 If yes go to step 4 else go
to step 5.
Step 4 : Print “Number is Even”. Go to step 6 Step 5 :
Print ”Number is Odd”.
Step 6 : Stop.
5
Flowchart to check Greatest Number of Three:
Step 1 : Start
Step 2 : Take input for a number from user as ‘a’.
Step 3 : Take input for a number from user as ‘b’.
Step 4 : Take input for a number from user as ‘c’.
Step 5 : Check whether a>b If yes go to step 6 else go to step
7.
6
Step 6 : Check whether a>c If yes go to step 8 else go to step
10.
7
Flowchart to check Given Year is Leap or Not:
Step1 : Start
Step2 : Take input for a number from user as a.
Step3 : Check whether ((a%4==0 and a / 100!=0) or (
a%400==0)) If yes go to step 4 else go to step 5.
Step4 : Print “Year is a leap year”. Go to step 6
Step5 : Print ”Year is not a leap yeat”.
Step6 : Stop.
8
Flowchart to print n Natural Number:
9
Algorithm to print n Natural Number:
Step 1: Start
Step 2: Assign i=1
Step 3: Take input for a number from user as ‘n’.
Step 4: Repeat step 5&6 until i>n reach
Step 5: Print i
Step 6: Compute i = i + 1
Step 7: Stop
10
Flowchart to print n Even Number:
Step 1: Start
Step 2: Assign i = 1
Step 3: Take input for a number from user as ‘n’.
Step 4: Repeat step 5&6 until I > n reach
Step 5: Check whether i % 2 = = 0 If yes print i else go to step
6
Step 6: Compute i = i + 1
Step 7: Stop
11
Flowchart to print n Odd Number:
12
Algorithm to print n Odd Number :
Step 1: Start
Step 2: Assign i=1
Step 3: Take input for a number from user as ‘n’.
Step 4: Repeat step 5&6 until i>n reach
Step 5: Check whether i%2!=0 If yes print i else go to step 6
Step 6: Compute i=i+1
Step 7: Stop
13
Flowchart to print n Prime Number:
14
Algorithm to print n Prime Number :
Step 1: Start
Step 2: Take input for a number from user as ‘r’.
Step 3: Assign i=1,a=1and c=0
Step 4: Repeat step 5,6,9,10 and 11 unƟl i>r reach.
Step 5 :Assign a=1
Step 6 : Repeat step 7&8 unƟl i>r reach.
Step 7 : Check whether a>b If yes assign c=c+1 else go to step
8.
Step 8 : Assign a=a+1
Step 9 : Check Whether c==2 If yes print value of I else go to
step 10.
Step 10 : Assign c=0
Step 11 : Compute i=i+1
Step 12 : Stop
15
Flowchart to check whether number is
Palindrome or not:
16
Algorithm to check whether number is
Palindrome or not :
Step 1: Start
Step 2: Take input for a number from user as ‘a’.
Step 3: Assign temp=a and b=0
Step 4: Repeat step 5,6,7 until a==0 reach.
Step 5 : Assign r=a%10
Step 6 : Assign b=(b*10)+r
Step 7 : Assign a=a/10
Step 8 : Check Whether temp==b If go to step 9 else go to
step 10
Step 9 : Print ”number is pallindrome”. Go to step 11
Step 10 : Print “Number is not Pallindrome”.
Step 11 : Stop
17
Flowchart to check whether number is
Amstrong or not:
18
Algorithm to check whether number is
Amstrong or not :
Step 1: Start
Step 2: Take input for a number from user as ‘n’.
Step 3: Assign temp=n ,c=0 ,b=0 and d=n
Step 4: Repeat step 5 and 6 until n==0 reach.
Step 5 :Assign n=(floora n/10)
Step 6 : Assign c=c+1
Step 7 : Repeat step 8,9 and 10 unƟl d==0 reach.
Step 8 : Assign r=d%10
Step 9 : Assign b=b+(r**c)
Step 10 : Assign d=floor(d/10)
Step 11 : Check Whether temp==b If yes go to step 12 else
step 13
Step 12 : Print ”number is Amstrong”. Go to step 14
Step 13 : Print “Number is not Amstrong”.
Step 14 : Stop
19
Flowchart to check whether number is Perfect
or not:
20
Algorithm to check whether number is Perfect
or not :
Step 1: Start
Step 2: Take the input for a number from the user as ‘p’.
Step 3: Assign i=1 and sum=0
Step 4: Repeat steps 5 and 6 until i==p reach.
Step 5 : Check Whether p%i==0 If yes assign sum=sum+i else
step 6
Step 6 : Assign i=i+1
Step 7 : Check Whether sum==p If yes go to step 8 else step 9
Step 8 : : Print ”number is Perfect”. Go to step 10
Step 9 : Print “Number is not Perfect”.
Step 10 : Stop
21
Flowchart to print n Fibonacci Series:
22
Algorithm to Print Fibonacci Series :
Step 1: Start
Step 2: Take the input for a Range from the user as ‘r’.
Step 3: Assign f1=0 and f2=1 and i=2
Step 4: Print f1 and f2
Step 5 : Repeat steps 6, 7, 8 and 9 until f==i reach
Step 6 : Assign f1=f1+f2
Step 7 : Print f1
Step 8 : Assign f2+f1
Step 9 : Assign i=i+1
Step 10 : Stop
23
Flowchart to take Input n print an Array:
24
Algorithm to take Input and Print an Array :
Step 1: Start
Step 2: Take the input for a size of array from the user as ‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Assign b=1 .
Step 8: Repeat steps 9 and 10 until b>r reach.
Step 9 : Print array as a[b].
Step 10 : Assign b=b+1
Step 11 : Stop
25
Flowchart to take Input and print Sum of an
Arrar:
26
Algorithm to take Input and Print sum of an
Array :
Step 1: Start
Step 2: Take the input for a size of array from the user as ‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Assign b=1 .
Step 8: Repeat steps 9 and 10 until b>r reach.
Step 9 : Print array as a[b].
Step 10 : Assign b=b+1
Step 11 : Assign b=1 and total=0
Step 12 : Repeat steps 13 and 14 until b>r reach.
Step 13 : Assign total=total+a[b]
Step 14 : Assign b=b+1
Step 15 : Print value of total
Step 16 : Stop
27
Flowchart to Search an element in an Array:
28
Algorithm to Search an element in an Array :
Step 1: Start
Step 2: Take the input for a size of array from the user as ‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Assign b=1 .
Step 8: Take the input for the element to be found in array
from the user as ‘s’.
Step 9: Repeat steps 9 and 10 until b>r reach.
Step 10 : Check whether a[b]==s If yes Print “Element found
at ”+b
Step 11 : Assign b=b+1
Step 12 : Stop
29
Flowchart to print Greatest Element is an
Array:
30
Algorithm to Print greatest element in an
Array:
Step 1: Start
Step 2: Take the input for a size of array from the user as
‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Assign b=1 and L= a[1].
Step 8: Repeat steps 9 and 10 until b>r reach.
Step 9 : Check Whether a[b]>L If yes Assign L=a[b] else
got to step 10
Step 10 : Assign b=b+1
Step 11 : Print value of L
Step 11 : Stop
31
Flowchart to print Smallest number in an
Array:
32
Algorithm to find out the Smallest Element in
an array:
Step 1: Start
Step 2: Read the size of the array from the user, say ‘n’
Step 3: Declare an array of size n, say a[n]
Step 4: Initialize loop variable, i = 0
Step 5: Repeat while i < n:
5.1: Read the array element at position ‘i’
5.2: Increment i by 1
Step 6: Initialize smallest element, min = a[0]
Step 7: Initialize loop variable, i = 0
Step 8: Repeat while i < n:
8.1: If a[i] < min, then:
8.1.a: min = a[i]
8.2: Increment i by 1
Step 9: Print the smallest element, min
Step 10: Stop
33
Flowchart to print n Factorial Number:
34
Algorithm to Print n Factorial Number :
Step 1: Start
Step 2: Take input for a number from user as ‘r’.
Step 3: Assign i=1 and f=1
Step 4: Repeat step 5, 6, 7, 10 and 11 until i>r reach.
Step 5 :Assign o=i
Step 6 : f=o
Step 7 : Repeat step 8 and 9 until f==1 reach.
Step 8 : Assign f=f-1
Step 9 : Assign o=o*f
Step 10 : Print value of o
Step 10 : Assign i=i+1
Step 11 : Stop
35
Flowchart to add an element in end of an
Array:
36
Algorithm to add an element in end of an
Array:
Step 1: Start
Step 2: Take the input for a size of array from the user as ‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 unƟl b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Take input from the user for the element to inserted as
‘c’.
Step 8: Assign r=r+1 , b=1 , a[r]=c Step 8: Repeat steps 9 and
10 unƟl b>r reach.
Step 9 : Print array as a[b].
Step 10 : Assign b=b+1
Step 11 : Stop
37
Flowchart to add an Element in Start of an
Array:
38
Algorithm to add an element in Start of an
Array:
Step 1: Start
Step 2: Take the input for a size of array from the user as
‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Take input from the user for the element to
inserted as ‘c’.
Step 8: Assign r=r+1 , b=1
Step 9: Repeat steps 9 and 10 until b>r reach.
Step 10 : Assign a[r]=a[r-1]
Step 11 : Assign b=b+1
Step 12 : Assign b=b+1 and a[1]=c
Step 13: Repeat steps 13 and 14 until b>r reach.
Step 14: Print array as a[b].
Step 15 : Assign b=b+1
Step 16 : Stop
39
Flowchart to print an A.P. Series:
40
Algorithm to print an A.P Series :
Step 1: Start
Step 2: Take the input for first number from the user as ‘a’.
Step 3: Take the input for Common Difference from the user
as ‘d’.
Step 4: Take the input for first number from the user as ‘n’.
Step 5 : Assign i=0
Step 6 : Repeat steps 7, 8 and 9 until i>n reach
Step 7 : Print value of a
Step 8 : Assign a=a+d
Step 9 : Assign i=i+1
Step 10 : Stop
41
Flowchart To add an Element in Middle of an
Array:
42
Algorithm to add an element in middle of an
Array :
Step 1: Start
Step 2: Take the input for a size of array from the user as
‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Take input from the user for the element to
inserted as ‘c’.
Step 8: Assign r=r+1 , b=1,k=floor(r/2)
Step 9: Repeat steps 9 and 10 until b>r reach.
Step 10 : Assign a[r]=a[r-1]
Step 11 : Assign b=b+1
Step 12 : Assign b=b+1 and a[k]=c
Step 13: Repeat steps 13 and 14 until b>r reach.
Step 14: Print array as a[b].
Step 15 : Assign b=b+1
Step 16 : Stop
43
Flowchart toad an element at an index of an
Array:
44
Algorithm to add an element at an index of an
array:
Step 1: Start
Step 2: Take the input for a size of array from the user as ‘r’.
Step 3: Assign b=1 .
Step 4: Repeat steps 5 and 6 until b>r reach.
Step 5 : Take input for array as a[b].
Step 6 : Assign b=b+1
Step 7 : Take input from the user for the element to inserted
and index number as ‘c’ and ‘p’ respectively .
Step 8: Assign r=r+1 , b=1
Step 9: Repeat steps 9 and 10 until b>r reach.
Step 10 : Assign a[r]=a[r-1]
Step 11 : Assign b=b+1
Step 12 : Assign b=b+1 and a[p]=c
Step 13: Repeat steps 13 and 14 until b>r reach.
Step 14: Print array as a[b].
Step 15 : Assign b=b+1
Step 16 : Stop.
45
Flowchart to Print Sum of Two Numbers:
Step 1 : Start
Step 2 : Take input a number from user as ‘a’.
Step 3 : Take input a number from user as ‘b’.
Step 4 : Assign c = a + b.
Step 5 : Print value of c.
Step 6 : Stop.
46