Table of Contents
Algorithms can be defined as the set of instructions structured to solve a problem. It is a step-by-step procedure to solve the problem. These steps are generally written in English to understand them easily and later convert them into computer programs. These steps together are called algorithms.
Let us consider an example, suppose you went shopping and want to know the amount you spent. So, you take out the shopping list and start adding the prices to your calculator.The same work can be done by designing an algorithm that adds your total amount.
Algorithm
1. Start 2. Assign a variable to each item (item1 name,item2 name,….). 3. Create a variable “total” which will store the total price. 4. Add all the “items” and store it to “total”. 5. Display “total”. 6. Stop.
Here is a C program to implement the above algorithm
#include <stdio.h>
int main() {
int milk, rice, potato, totalPrice;
printf("Enter the price of milk:\n");
scanf("%d", &milk);
printf("Enter the price of rice:\n");
scanf("%d", &rice);
printf("Enter the price of potato:\n");
scanf("%d", &potato);
totalPrice = milk + rice + potato;
printf("Total Price = %d\n", totalPrice);
return 0;
}
Output
Enter the price of milk:
43
Enter the price of rice:
52
Enter the price of potato:
33
Total Price = 128
What did you think?
Similar Reads
-
Randomized Version of Quick Sort Explanations
The Randomized Version of the QuickSort algorithm is a variation of the normal QuickSort algorithm. In Randomized QuickSort, the pivot… -
Pseudocode of QuickSort with Its analysis
QuickSort algorithm uses the divide and conquers method to sort an Array. It contains a function that is used to… -
Pseudocode of Insertion sort with Time Complexity Analysis
Insertion Sort is a simple sorting algorithm that picks an element from the unsorted position and inserts it into its… -
Explain Recursion Tree in Algorithm with Example
A recursion tree visually represents the recursive calls made in a recursive algorithm. It helps to illustrate how the recursive… -
Divide and Conquer Recurrences with Examples
Divide and Conquer recurrences are mathematical equations. It describes the time complexity of divide-and-conquer algorithms. Divide and conquer is a… -
Optimality and Reduction Of Algorithm with Examples
Optimality and reduction are essential concepts in the design and analysis of an algorithm. They both play a crucial role… -
Complexity of an Algorithm: Time and Space Complexity
As we know that a by Designing an Algorithm, a problem can be solved. To perform some tasks based on… -
Characteristics of an algorithm with explanations
As we know that, algorithms provide us the procedure to solve any problem. Below are some characteristics that define a… -
What do you mean by an algorithm? Explain it with an example.
Algorithms can be defined as the set of instructions structuredto solve a problem. It is a step-by-step procedure to solve… -
DAA Unit 5: Selected Topic Previous year questions
What do you mean by String matching ? Also explain string, sub string and proper sub string.Explain Knuth-Morris-Pratt Algorithm and…