EXPERIMENT NO. 1
Aim: Write algorithm and draw flowchart of given problem.
Objectives: Understand how to write algorithm, flowchart for the solution of the problem and to optimize the same
Hardware requirements: Any CPU with Pentium Processor or similar, 256 MB RAM or more, 1 GB Hard Disk or more.
Software requirements: Windows 64 bit / Ubuntu 14 Operating System, MS office 2010 or later, Open Office for Ubuntu
Theory:
Algorithms and Flowcharts in programming language: A typical programming task can be divided into two phases:
- Problem solving phase: produce an ordered sequence of steps that describe solution of problem. This sequence of steps is called an algorithm
- Implementation phase: implement the program in some programming language
Steps in Problem Solving
- First produce a general algorithm (one can use pseudocode)
- Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language.
Flowchart: A schematic representation of a sequence of operations, as in a manufacturing process or computer program. In technical terms, a graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.
A Flowchart
- shows logic of an algorithm
- emphasizes individual steps and their interconnections
- e.g. control flow from one action to the next
Algorithms are mainly used for mathematical and computer programs, while flowcharts can be used to describe all sorts of processes: business, educational, personal and of course algorithms. So flowcharts are often used as a program planning tool to visually organize the step-by-step process of a program.
Flowchart Symbols:
Solve any three of the following
- Check if given number is palindrome or not
- Check if given number is Armstrong or not
- Check if given number is prime or not
- Display addition of digits in given number
Question: Display addition of digits in given number
Algorithm:
Step 1: Start
Step 2: Input Number “num”
Step 3: sum = 0
Step 4: rem = num % 10;
Step 5: sum = sum + rem;
Step 6: num = num / 10;
Step 7: if (num != 0) then goto Step 4
Step 8: Print sum
Step 9: End
Flowchart:
Question: Check if given number is palindrome or not
Algorithm:
Step 1: Start
Step 2: Input Number “num”
Step 3: sum = 0, m=num
Step 4: rem = num % 10;
Step 5: sum = sum *10 + rem;
Step 6: num = num / 10;
Step 7: if (num != 0) then
goto Step 4
Step 8: if (num==m) then Print “Number is Palindrome”
else Print “Number is not Palindrome”
Step 9: End
Flowchart:
Question: Check if given number is Armstrong or not
Algorithm:
Step 1: Start
Step 2: Input Number “n”
Step 3: sum = 0, m=n
Step 4: rem = n % 10;
Step 5: sum = sum + rem * rem * rem;
Step 6: n = n / 10;
Step 7: if (n != 0) then
goto Step 4
Step 8: if (sum==m) then Print “Number is Armstrong”
else Print “Number is not Armstrong”
Step 9: End
Flowchart:
Question: Check if given number is Prime or not
Algorithm:
Step 1: Start
Step 2: Input Number “n”
Step 3: m=2
Step 4: rem = n % m;
Step 5: if( rem== 0 ) then goto Step 6
else
m=m+1
goto Step 4
Step 6: if(n==m) then Print “Number is Prime”
else Print “Number is not Prime”
Step 7: End
Flowchart:
Conclusion: In this experiment, we have studied about writing algorithm and drawing flowchart for given problem.
R. No. | Name of Student | Date of Performance | Date of Evaluation | Grade | Sign of student | Sign of Faculty |