Computer Science, asked by anandprakashinjsr, 1 month ago

Q basic WAP to store a number. Now display it’s half if it is an even number otherwise

display it’s one-third.​

Answers

Answered by agrim28
0

Answer:

INPUT # and LINE INPUT

INPUT # uses an open file stream to collect data from the file itself. The file may be a data file, a bitmap, or a text file. The syntax is:

INPUT #file_stream, variable1 ; variable2$ ' more variables can be taken.

LINE INPUT is used to collect an entire line of a text file. Syntax:

LINE INPUT 1,file_line '1 is the file stream number. Can be any other number too.

mark me as brain list please:D

Answered by anindyaadhikari13
1

\texttt{\textsf{\large{\underline{Solution}:}}}

The given co‎de is written in QBASIC.

CLS

INPUT "Enter a number: "; N

IF N MOD 2 = 0 THEN

   PRINT "Half of the number is: "; N / 2

ELSE

   PRINT "One third of the number is: "; N / 3

END IF

END

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • Line 1: Clears the screen.
  • Line 2: Accept the number.
  • Line 3: Check if number is divisible by 2 or not.
  • Line 4: If true, display the half of the number.
  • Line 5: Else block.
  • Line 6: As the condition is not true i.e. the number is odd, display its one-third.
  • Line 7: End of IF block.
  • Line 8: End of program.

See the attachment for output.

Attachments:
Similar questions