1 / 4

QUESTION 1

QUESTION 1

inga
Download Presentation

QUESTION 1

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. QUESTION 1 Design an algorithm that will accept three values as inputs. The first value would be one of four operation codes, either “A” (addition), “S” (subtraction), “M” (multiplication), or “D” (division). The other two input values will be numbers. The computer is to perform a computation on the two numbers as determined by the operation code. The result of the computation, as well as the original inputs, is to be written as output. An error message should be output if the operation code is invalid.

  2. CASE CONTROL STRUCTURE • We can replace the nested IFTHENELSE structure with a CASE control structure. • Although the CASE structure serves as alternative for a nested IFTHENELSE control structure, it cannot be used in place of a sequential IFTHENELSE pattern. • Let us look at the structure of a CASE: • START • DECLARE age AS integer • READ age • CASENTRY age • CASE 1 • PRINT “I am one” • CASE 2 • PRINT “I am 2” • CASE 3 • PRINT “I am three” • CASE other • PRINT “ I am older than 3” • ENDCASE • STOP

  3. CASE CONTROL STRUCTURE • The flowchart structure is as follows: START READ age Age? 3 other 1 2 PRINT “ I am one” PRINT “ I am two” PRINT “ I am three” PRINT “ I am older than 3” STOP

  4. CASE CONTROL STRUCTURE • Let us look at the structure of a CASE in C: #include<conio.h> #include<stdio.h> int main () { int age; printf("Please enter your age "); scanf("%d", &age); switch(age) { case 1: printf("I am one"); break; case 2: printf("I am two"); break; case 3: printf("I am three"); break; default: printf("I am older than 3"); break; } getch(); return 0; }

More Related