Skip to main content

what is a algorithm? Its properties and give examples.

 

An algorithm is a step by step process to solve a problem using a finite number of steps. Algorithms are used in mathematical computing etc to carry out calculations or data processing.
The algorithm is developed using pseudocode.
Pseudocode: It is an artificial and informal language that helps programmers to develop algorithms.  
Pseudocode programs are not executed on computers but they are used in developing algorithms. 
The algorithms must satisfy the following properties

Properties of Algorithms
Input – the algorithm must accept zero or more inputs.
Output - must produce at least one output.
Definiteness -Each instruction is clear.
Finiteness -An algorithm should terminate after a finite number of steps. It should not enter into an infinite loop.
Effectiveness – Each operation must be simple and should complete in a finite time algorithm: examples of algorithms:

1.Addition of two numbers
Step 1: Start
Step 2: Declare variables num1, num2, and sum.
Step 3: Read values into num1 and num2.
Step 4: sum = num1+num2
Step 5: print sum
Step 6: Stop

2.Algorithm: Area of a circle
Step 1: Start
Step 2: Declare variables radius and Area
Step 3: Read value into the radius
Step 4: Area = 3.14*radius*radius
Step 5: print Area
Step 6: Stop

3.Algorithm: Largest among 3 numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop

4.Algorithm to print "n" natural numbers
Step 1: Start
Step 2: Declare n, i
Step 3: Assign i=1
Step 4: Read value into n
Step 5: Repeat step 5.1 and 5.2 until i<=n
5.1 Print i
5.2 Compute i=i+1
Step 7: Stop

5.Algorithm to sum "n" natural numbers
Step 1: Start
Step 2: Declare variables n, sum and i.
Step 3: Initialize variables or Assign
sum = 0
i = 1
Step 4: Read value into n
Step 5: Repeat 5.1 and 5.2 until i <= n
5.1 : sum = sum+i
5.2 : i = i+1
Step 6: Display sum
Step 7: Stop

Comments

Popular posts from this blog

C program to calculate Compound Interest.

C program to calculate Compound Interest program:2 Write a C program to input principle (amount), time, and rate (P, T, R) and find Compound Interest. How to calculate compound interest in C programming. Logic to calculate compound interest in the C program. Compound Interest formula Formula to calculate compound interest annually is given by. Where, P  is principle amount R  is the rate and T  is the time span

leap year program in java language for btech students in a easy approach.

  Java Program to Find if a given Year is a Leap Year for BTech CSE students. Leap Year contains 366 days, which comes once every four years. Every leap year corresponds to these facts :  A century year is a year ending with 00. A century year is a leap year only if it is divisible by 400. A leap year (except a century year) can be identified if it is exactly divisible by 4. A century year should be divisible by 4 and 100 both. A non-century year should be divisible only by 4. https://ide.geeksforgeeks.org/S3DSLXo19k <<<<<<< check out the program in the compiler for clarity.

write a c program to find a distance when initial velocity ,acceleration and time is given.

 c program is a beginner's program language. If you want to learn c program language click here for notes . I will publish the programs daily check out and practice for a better result, practice makes a man perfect. practice program 1 : write a program to find a distance when initial velocity, acceleration, and time are given.