1 / 10

Coding Examples and Practice Problems - Even/Odd, Circle Area, Greater of Two, Triangle Classification

Practice coding with problems like determining even/odd, calculating circle area, finding the greater of two numbers, and classifying triangles based on side lengths. Prepare for an upcoming quiz by solving flowcharts and writing pseudo code in C++. Utilize Lab exercises for hands-on learning.

pcherry
Download Presentation

Coding Examples and Practice Problems - Even/Odd, Circle Area, Greater of Two, Triangle Classification

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 2 Examples Pseudo code and flowcharts

  2. Problem 1 • Read a number as input and then print if it is even or odd

  3. Problem 1 : Flowchart and pseudo code Pseudo code: read number get the remainder when the number is divided by 2 if remainder is 0 print “number is even” else print “number is odd”

  4. Problem 2 • Read the radius of circle and print the area and circumference only if the value of the radius is more than zero.

  5. Problem 2 Pseudo code: read radius if radius <= 0 print “Radius cannot be negative or zero” exit if radius > 0 calculate area calculate circumference print area print circumference

  6. Problem 3 • Take two numbers as input and print the greater of the two. If numbers are equal print “numbers are equal”.

  7. Problem 3 Pseudo code: read n1, n2 if n1 equals n2 print “numbers are equal” exit if n1 > n2 print “n1 is greater” else print “n2 is greater”

  8. Problem 4 • Read the length of the three sides of a triangle and print if it the triangle is an equilateral or isosceles or scalene triangle. equilateral – all sides are equal isosceles – any two sides are equal scalene – all sides have different length Try this problem as an exercise and show it to me in the labs

  9. Quiz 1 • Next week at this lecture time • 45 mins, 5% of the course • Lecture 1 + Lecture 2 part (what we did today) • MCQs, short answer, flowcharts, pseudo code and c++ programs

  10. Lab talk • DevC++ is already setup for most of you • Always come to lab with the lecture printout or PPT • Lab exercises are related directly to lecture and are the practical part of the lecture • YOU MUST TRY TO SOLVE THE LAB EXERCISES BEFORE YOU COME TO LAB – TRY! • Save and organize your C++ programs into folders like lab 1, lab 2 – you will need them later…. • There are lab exams also .. later • Lab exercises always available on the website a couple of days before the lab

More Related