Algorithm

An algorithm is a finite set of instructions that if we followed in sequence it accomplish a particular task in finite time and requires finitespace in memory.


• There are in general five criteria which an algorithm must satisfy-

1. Input

2. Output

3. Definitness

4. Finiteness

5. Effectiveness


Algorithm to add two numbers

Step 1: Input first number as P

Step 2: Input second number as Q

Step 3: Set Sum=P+Q

Step 4: Print Sum

Step 5: End.

Program to add two numbers

Input:

        #include < stdio.h >
        int main()
                {    
                 int number1, number2, sum;
                 printf("Enter two integers: ");
                 scanf("%d %d", &number1, &number2);
                                                   // calculate the sum
                 sum = number1 + number2;      
                 printf("%d + %d = %d", number1, number2, sum);
                 return 0;
                } 

Output:


            Enter two integers: 12
            11
            12 + 11 = 23