Flowchart and Algorithm

Hii from Team(S.A.O.P)

Today's blog is all about Flowchart and Algorithm..as we all know flowchart and Algorithm help user/Programmers to understand the Program's behavior (Flow of programs)...
let's talk in more detail.

Flowchart:

flowchart is a type of diagram that represents an algorithm, workflow or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows..Using different Symbols.


Basic symbol:









Algorithm:

Basically, Algorithm means Set of Step is using for solving any kind of problem...
Let see the proper Definition of Algorithm  

An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem, based on conducting a sequence of specified actions. A computer program can be viewed as an elaborate algorithm. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem.

Example of Flowchart and Algorithm: 

question: menu Driven program that performs basic maths operation such as Addition,Subtraction, Multiplication, and Division.

//first we gonna draw FlowChart then we gonna write Algorithm then we code the program.

FlowChart



ALGORITHM:


1. Start

2. Enter a, b values.

3. Print ‘MENU’.
    (i) Print ‘+ Addition’.
   (ii) Print ‘- Subtraction’.
  (iii) Print ‘* Multiplication’.
   (iv) Print ‘/ Division’.
    (v) Print ‘% Remainder’.
   (vi) Print ‘E Exit’.
4. Print ‘Enter your choice’.
5. If op==’E’ then goto step 8 otherwise follow the below steps
6. Switch(op)
    a. case +:
     i. Print ‘Addition’.
    ii. c=a+b.
   iii. Print ‘Sum=’c.
    iv. break
    b. case -:
     v. Print ‘Subtraction’.
    vi. c=a-b.
   vii. Print ‘Difference=’c.
  viii. break
    c. case *:
    ix. Print ‘Multiplication’.
     x. c=a*b.
    xi. Print ‘Product=’c.
   xii. break
    d. case /:
  xiii. Print ‘Division’.
   xiv. c=a/b.
    xv.       Print ‘Quotient=’c.
   xvi. break
   e. case %:
  xvii. Print ‘Remainder’.
 xviii. c=a%b.
   xix. Print ‘Remainder=’c.
    xx. break
   f. default:
   xxi. Print ‘Invalid Option’.
  xxii. break
7. while(1) then goto step 3.
8. Stop.


PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<math.h>
void main(int argc, char**argv)
{
    int a, b, c;
    char op;
    printf("Enter a and b:");
    scanf("%d%d",&a,&b);
    do
    {
        printf("\n\nMENU\n");
        printf("+ Addition\n");
        printf("- Subtraction\n");
        printf("* Multiplication\n");
        printf("/ Division\n");
        printf("%% Remainder\n");
        printf("E Exit\n");
        printf("Enter your choice :");
        getchar();
        op=getchar();
        if(op=='E'||op=='e')
            exit(1);
        switch(op)
        {
        case '+':
            printf("Addition\n");
            c=a+b;
            printf("Sum=%d\n",c);
            break;
        case '-':
            printf("Subtraction\n");
            c=a-b;
            printf("Difference=%d\n",c);
            break;
        case '*':
            printf("Multiplication\n");
            c=a*b;
            printf("Product=%d\n",c);
            break;
        case '/':
            printf("Division\n");
            c=a/b;
            printf("Quotient=%d\n",c);
            break;
        case '%':
            printf("Remainder\n");
            c=a%b;
            printf("Remainder=%d\n",c);
            break;
        default:
            printf("Invalid Option\n");
            break;
        }
    }while(1);
}
sorry for bad quality of the picture...Thanks for reading this blog
This blog is presented by(S.A.O.P) 127.0.0.1Is Heaven

Comments