Вы находитесь на странице: 1из 46

1.3.

1 Algorithm & Flowchart to find the sum


of two numbers
• Step-1 Start
• Step-2 Input first numbers say A
• Step-3 Input second number say B
• Step-4 SUM = A + B
• Step-5 Display SUM
• Step-6 Stop
1.3.1 Algorithm & Flowchart to find the sum
of two numbers
1.3.1 Algorithm & Flowchart to find the sum
of two numbers
• Algorithm
• Step-1 Start
• Step-2 Input two numbers say A & B
• Step-3 SUM = A + B
• Step-4 Display SUM
• Step-5 Stop
1.3.1 Algorithm & Flowchart to find the sum
of two numbers
1.3.1 Algorithm & Flowchart to find the sum
of two numbers
1.3.2.1 Determining if a number is +ve / -ve
1.3.2.2 Determining if a number even / odd
• Step 1 : Start
• Start 2 : Read n
• Start 3 : if (n%2 == 0), Write " even number" else Write " odd
number"
• Start 4 : Stop
1.3.2.2 Determining if a number even / odd
1.3.3.1 lgorithm & Flowchart to find the
largest of two numbers
• Algorithm
• Step-1 Start
• Step-2 Input two numbers say
• NUM1,NUM2
• Step-3 IF NUM1 > NUM2 THEN
• print largest is NUM1
• ELSE
• print largest is NUM2
• ENDIF
• Step-4 Stop
1.3.3.1 lgorithm & Flowchart to find the
largest of two numbers
1.3.3.2 Algorithm & Flowchart to find the
largest of three numbers
• Algorithm & Flowchart to find the • ENDIF
largest of three numbers • GO TO Step-6
• Algorithm • Step-5 IF num1>num3 THEN
• Step-1 Start • print num1 is largest
• Step-2 Read three numbers say • ELSE
num1,num2, num3
• print num3 is largest
• Step-3 if num1>num2 then go to
step-5 • ENDIF
• Step-4 IF num2>num3 THEN • Step-6 Stop
• print num2 is largest
• ELSE
• print num3 is largest
1.3.3.2 Algorithm & Flowchart to find the
largest of three numbers
1.3.3.2 Algorithm & Flowchart to find the
largest of three numbers (an another way)
• Algorithm
• Step-1 Start
• Step-2 Read three numbers say A,B,C
• Step-3 BIG = A
• Step-4 IF B > BIG THEN
• BIG = B
• ENDIF
• Step-5 IF C >BIG THEN
• BIG = C
• ENDIF
• Step-6 Write BIG
• Step-7 Stop
1.3.3.2 Algorithm & Flowchart to find the
largest of three numbers (an another way)
1.3.4.1 Algorithm & Flowchart to find sum of
series 1+2+3+…..+N
• Algorithm
• Step-1 Start
• Step-2 Input Value of N
• Step-3 I = 1, SUM=0
• Step-4 IF (I >N) THEN
• GO TO Step-8
• ENDIF
• Step-5 SUM = SUM + I
• Step-6 I = I + 1
• Step-7 Go to step-4
• Step-8 Display value of SUM
• Step-9 Stop
1.3.4.1 Algorithm & Flowchart to find sum of
series 1+2+3+…..+N
1.3.4.3 Sum of digits of a given number
• Detailed Algorithm:

• Step 1: Input N
• Step 2: Sum = 0
• Step 3: While (N != 0)
• Rem = N % 10;
• Sum = Sum + Rem;
• N = N / 10;
• Step 4: Print Sum
1.3.4.2 sum of given n numbers
1.3.4.2 sum of given n numbers
1.3.4.3 Sum of digits of a given number
• Get the number
• Declare a variable to store the sum and set it to 0
• Repeat the next two steps till the number is not 0
• Get the rightmost digit of the number with help of remainder ‘%’
operator by dividing it with 10 and add it to sum.
• Divide the number by 10 with help of ‘/’ operator
• Print or return the sum
1.3.4.3 Sum of digits of a given number
1.3.4.4 print sum of first and last digit of a
number.
• Step 1: Read a number, num
• Step 2: Compute num1=num%10
• Step 3: Assign num2=num
• Step 4: Repeat step 5 while num2=>10
• Step 5: Compute num2=num2/10
• Step 6: print num1+num2
• Step 7: Stop
1.3.4.4 print sum of first and last digit of a
number.
1.3.5.3 Algorithm & Flowchart to find
Factorial of number n ( n!=1x2x3x…n)
• Algorithm
• Step-1 Start
• Step-2 Read number N
• Step-3 FACT=1 CTRL=1
• Step-4 WHILE (CTRL <= N)
• DO
• FACT=FACT*I
• CTRL=CTRL+1
• DONE
• Step-5 Display FACT
• Step-6 Stop
1.3.5.3 Algorithm & Flowchart to find
Factorial of number n ( n!=1x2x3x…n)
1.3.5.4 Algorithm & Flowchart to find if a
number is prime or not
• Algorithm • ENDIF
• Step-1 Start • Step 6 IF ( NUM % I ==0) THEN
• Step-2 Input NUM • Write NUM is Not Prime
• Step-3 R=SQRT(NUM) • Stop
• Step-4 I=2 • ENDIF
• Step-5 IF ( I > R) THEN • Step-7 I = I + 1
• Write NUM is Prime Number • Step-8 Go to Step-5
• Stop
1.3.5.4 Algorithm & Flowchart to find if a
number is prime or not
1.3.5.5 Algorithm & Flowchart to find all the
factor/divisor of a number
• Algorithm
• Step-1 Start
• Step-2 Read number N
• Step-3 D=1
• Step-4 WHILE (D< N)
• DO
• IF ( N % D ==0) THEN
• PRINT D
• ENDIF
• D=D+1
• DONE
• Step-5 Stop
1.3.5.5 Algorithm & Flowchart to find all the
factor/divisor of a number
1.3.5.6 Algorithm & Flowchart to find
Factorial of a number,
• step 1. Start
step 2. Read the number n
step 3. [Initialize]
        i=1, fact=1
step 4. Repeat step 4 through 6 until i=n
step 5. fact=fact*i
step 6. i=i+1
step 7. Print fact
step 8. Stop
[process finish of calculate the factorial value of a number]
1.3.5.6 Algorithm & Flowchart to find
Factorial of a number,
1.3.5.6 Algorithm & Flowchart to find
Factorial of a number,
1.3.5.7 Algorithm & Flowchart to find
number is prime or not 
• Step 1:  Input N & M
• Step 2:  While (N < M)
•                          I=2
• Step 4:                  While (I<N)
• Step 5:                                 IF N%I == 0
•                                                      goto Step 7
• Step 6:                           I++
• Step 7:        IF I==NUM
•                                 Print NUM
 Step 7:   N++ 
• Flowchart:-
1.3.5.7 Algorithm & Flowchart to find
number is prime or not 
1.3.5 9 Algorithm & Flowchart to find GCD
and LCM of two number
• Algorithm • Step-5 WHILE (r != 0)
• Step-1 Start • DO
• Step-2 Read two number A, B • N=D
• Step-3 IF (A > B) THEN • D=r
• N =A • r =N%D
• D=B • DONE
• ELSE • Step-6 gcd=d
• N=B • Step-7 lcm = (a*b)/gcd
• D=A • Step-8 Display gcd, lcm
• ENDIF • Step-9 Stop
• Step-4 r=N/D
1.3.5 9 Algorithm & Flowchart to find GCD
and LCM of two number
1. Problem Definition: Write an algorithm to add given two numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Total = A+B.
Step 4: Display Total.
Step 5: Stop.
4. Problem Definition: Write an algorithm to multiply given two numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Answer = A * B.
Step 4: Display Answer.
Step 5: Stop.
3. Problem Definition: Write an algorithm to find factorial of a given number.

Step 1: Start
Step 2: Declare variables: N, fact,  i.
Step 3: Initialize variables
            fact = 1
      i=1
Step 4: Read value of N from user.
Step 5: Repeat following steps until i = N
            fact =  fact * i
      i=i+1
Step 6: Print fact variable.
Step 7: Stop
STEP 1.      big <-- 0, num1 <-- 0, num2 <-- 0
STEP 2.       Read num1, num2
STEP 3.       big <-- num1
STEP 4.       Is (num2 > big) Then
Begin
big <-- num2
End
            STEP 5.       Print big
• ALGORITHM TO FIND WHETHER NUMBER IS POSITIVE, NEGATIVE OR ZERO (IS ELSE-IF ELSE STRUCTURE)
• STEP 1.      Num <-- 0
• STEP 2.      Read Num
• STEP 3.      Is (Num > 0) Then
•    Begin
•          Print “Positive”
•    End
• Else if (Num<0) Then
•    Begin
•         Print “Negative”
•    End
•   Else
•      Begin
•         Print “Zero”
•      End
• ALGORITHM TO FIND SUM OF FIRST N NUMBERS USING FOR AND WHILE
• Method 1 (FOR)

• STEP 1. Set I <-- 0, N <-- 0, Sum <-- 0


• STEP 2. Read N
• STEP 3. Repeat for I = 0, 1, … N – 1
• Begin
• Sum <-- Sum + I
• End
• STEP 4. Print Sum
ALGORITHM TO FIND SUM OF FIRST N NUMBERS USING
FOR AND WHILE

• ethod 2(WHILE)

• STEP 1. Set I <-- 0, N <-- 0, Sum <-- 0


• STEP 2. Read N
• STEP 3. while (I<=N-1)
• Begin
• Sum <-- Sum + I
• I<-- I+1
• End
• STEP 4. Print Sum
• FLOWCHART TO FIND SUM OF THE SERIES 1+3+5+7+….UPTO N TERMS
• ALGORITHM TO FIND SUM OF THE SERIES 1+3+5+7+….UPTO N TERMS

• STEP 1. I <-- 0, J<--1, Sum <-- 0, N <-- 0


• STEP 2. Read N
• STEP 3. While (I <= N-1)
• Begin
• Sum <-- Sum+ J
• J <-- J + 2
• I <-- I + 1
• End
• STEP 4. Print Sum

Вам также может понравиться