[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Practical 1 Algorithm

The document provides an overview of algorithms, defining them as a set of instructions for solving problems. It includes examples of algorithms for adding/subtracting two numbers, finding the largest of three numbers, and calculating the sum of 'N' numbers. Each example outlines a step-by-step process to achieve the desired outcome.

Uploaded by

sahilminz7488
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Practical 1 Algorithm

The document provides an overview of algorithms, defining them as a set of instructions for solving problems. It includes examples of algorithms for adding/subtracting two numbers, finding the largest of three numbers, and calculating the sum of 'N' numbers. Each example outlines a step-by-step process to achieve the desired outcome.

Uploaded by

sahilminz7488
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL-1

Write an algorithm for programmable problems Example for Reference:


• Add/subtract two numbers
• Find the largest/smallest of 3 numbers
• Calculate and print sum of 'N' numbers

What is Algorithm:

An algorithm is a set of instructions that are followed to perform a task or solve a problem.

Purpose:

Algorithms are used to perform calculations, find information in databases and more. They are a key
part of computer programming. Algorithms take inputs, run them through a series of steps, and produce
outputs.

Examples:

1. Write an algorithm to add/subtract two numbers.

Ans:

Step-1 :start.
Step-2: accept the first number from the user and store it in the variable num1.
Step -3: accept the second number from the user and store it in the variable num2.
Step-4: add num1 and num2 and store the result in the variable sum.
Step -5: subtract num1 and num2 and store the result in variable sub

2. Write an algorithm to find the largest of 3 numbers

Ans:

Step -1: Start


Step-2: Read the three numbers to be compared, i.e., x, y, and z.
Step-3: Check if x is greater than y. If true, check if x is greater than z. If true, print the value of x. If false,
print the value of z. If false, check if y is greater than z. If true, print the value of y. If false, print the value
of z.
Step -4: End

3. Calculate and print sum of 'N' numbers

Ans:
Step 1: Start
Step 2: Read number n
Step 3: Declare sum to 0 and i to 1
Step 4: Repeat steps 5 to 7 until i<=n
Step 5: update sum as sum = sum + i
Step 6: increment i
Step 7: Print sum
Step 8: Stop

You might also like