Computer Science, asked by rehangondal1234, 7 months ago

write a program called Print Number In Word which prints " one " ,"two ",........"Nine " ,"other" if the int variable " number is 1,2,.....9 or other respectively, use (a) a " nested -if " statement (b) a " switch - case " statement (c) Arrays .​

Answers

Answered by aviralrastogi0p4uudc
2

Answer:

a) using nested if

if ( n==1 ){

   print("One");}

else if ( n==2 ){

   print("Two");}

.

else{

   print("other");}

b) switch case

switch(n){

case 1: print("One"); break;

case 2: print("Two"); break;

.

default: print("other");

c) arrays (This works but not sure if teacher wanted it like this)

I am using python for here,

L = [ "One", "Two", ... "Nine" ] // basically create a 2d array or array of strings

print( L[ n-1 ])

Similar questions