Академический Документы
Профессиональный Документы
Культура Документы
• 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)
• ethod 2(WHILE)