Skip to main content

Algorithm


Algorithm


Write algorithm and draw flowchart of the following problem:
A) Find the largest and smallest number from the list of numbers
Answer:
01. Read a number if there no number go to step 7
02. Set largest and smallest to number
03. Read a card; if there are no more number go to step 6
04. If the number is greater than largest set largest to number and go to step 3
05. If the number is smaller than smallest set smallest to number and go to step 3
06. Print largest and smallest
07. stop
B) Count the total even numbers and odd numbers from the list of numbers
Answer:
01. Set Even and Odd equal to 0
02. Read the list; if there are no more number, go to step 5
03. If number is divide by 2 & no remainder, add one to the even counter and go to step 2
04. Add one to the Odd counter and go to step 2
05. Print
C) A file containing the records of product id and product price is given. Calculate the MRP value of the product after adding 1.5% vat with the product price.
Answer:
01. Initialize MRP to 0
02. Read the file, at EOF go to step 8
03. Multiply price by 1.5 and store into a
04. Divide a by 100 and store into c
05. Add c to product price
06. Print the results.
07. Go to step 2
08. Stop
D) Find the largest number of a, b and c.
Answer:
01. Read three numbers a, b, c
02. If a is greater than b and c than the largest number is a
03. If b is greater than a and c than the largest number is b
04. C Is the largest number
05. Stop
E) Calculate the summation from 1-100
Answer:
01. Initialize total to 0 and to 1
02. Add total by n
03. Increment n by 1
04. If n is less than 100 than go to step 2
05. Print total
06. Stop
F) Find those numbers from 50-100 which are divisible by 5
Answer:
01. Set n equal to 50
02. Divide n by 5 and set the remainder value to R
03. If R is 0 than Print n
04. Increment n by 1
05. If n is less than 101 than go to step 2
06. Stop

01. Compared three numbers a, b, c and find out the largest number
Step1 : Read the three number a, b, c
Step2 : If a is greater than b & c than a is the largest number and go to step 5
Step3 : If b is greater than a & c than a is the largest number and go to step 5
Step4 : c is the largest number
Step5 : stop/print

02. Read a number and find out it is even or odd
Step1 : read the number a
Step2 : divide a by 2
Step3 : if remainder is 0 than a is even; go to step 5
Step4 : a is odd
Step5 : stop/ print.

03. Find out the average of two numbers
Step1 : read the two number a, b
Step2 : add two number and store into c
Step3 : divide c by 2 and store d
Step4 : stop/ print.

04. Given a list of numbers. Find out how many are positive, negative & zeros
10, -3, 0, 8, -1, 15
Step1 : set positive, negative & zero equal to=0
Step2 : read a number if there are no number than go to step 6
Step3 : if the number is positive, add 1 to positive counter; go to step 1
Step4 : if the number is negative, add 1 to negative counter; go to step 1
Step5 : add 1 to zero counter
Step6 : print / stop

Comments

Popular posts from this blog

IDB HTML MCQ

Questions: 1. A webpage displays a picture. What tag was used to display that picture? a. picture b. image c. img d. src 2. <b> tag makes the enclosed text bold. What is other tag to make text bold? a. <strong> b. <dar> c. <black> d. <emp> 3. Tags and test that are not directly displayed on the page are written in _____ section. a. <html> b. <head> c. <title> d. <body> 4. Which tag inserts a line horizontally on your web page? a. <hr> b. <line> c. <line direction=”horizontal”> d. <tr> 5. What should be the first tag in any HTML document? a. <head> b. <title> c. <html> d. <document> 6. Which tag allows you to add a row in a table? a. <td> and </td> b. <cr> and </cr> c. <th> and </th> d. <tr> and </tr> 7. How can you make a bulleted list? a. <list> b. <nl> c. <ul> d. <ol> 8. Ho

Database Connection with PHP PDO MYSQL

PDO Connection MYSQLI // Create Connection with Pdo\ $dsn = "mysql:host=localhost; dbname=test;"; $db_user = "root"; $db_password = ""; try{     $conn = new PDO("$dsn", "$db_user","$db_password");    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     echo "Connected"; }catch(PDOException $a){     echo "Connection Failed". $a->getMessage(); }