Sunday, 2 July 2023

 

What is an Algorithm?

An algorithm is a set of instructions or steps that are used for problem-solving or to perform a computation.

 It is a well-defined, step-by-step procedure that is used to solve a problem or perform a computation.

Here is an example algorithm for converting the seed into a tree.





Step 1: Plant the seed in the soil.

Step 2: Water it regularly.

Step 3: Wait for the seed to germinate.

Step 4: Watch the seedling grow into a sapling.

Step 5: Provide support to the sapling if needed.

Step 6: Prune the sapling if needed.

Step 7:  Watch the sapling grow into a tree.

In technically,

Here is an example algorithm to add two numbers.

 Step 1: Start Step

 Step2: Declare variables num1, num2, and sum.

 Step 3: Read values num1 and num2.

Step 4: Add num1 and num2 and assign the result to the sum. sum←num1+num2

Step 5: Display the sum.

Step 6: Stop.

The sum of the two numbers program in C

#include <stdio.h>
int main() {    

    int number1, number2, sum;
   
    printf("Enter two integers: ");
    scanf("%d %d", &number1, &number2);
    sum = number1 + number2;      
    printf("The Sum of %d and  %d is %d",
number1, number2, sum);
    return 0;
}

Output:

Enter two integers: 2 8 The Sum of 2 and 8 is 10

No comments:

Post a Comment

Word Basic Exercise

Exercise 1: Opening a document Show and hide the ribbon Move, show, and hide options of Quick Access toolbar Exercise 2: Cre...