You are on page 1of 3

PRACTICE

 PROBLEMS  (ARRAYS  AND  STRINGS)  

1) Ask  the  user  for  10  integers  as  input.  Store  the  inputs  in  an  array  of  size  10.  Your  
program  should  then  find  the  minimum  and  maximum  values  stored  in  the  array,  
and  then  display  a  message  stating  the  aforementioned  values.  
 
Sample  Run:  
Enter  Integer  1>  50  
Enter  Integer  2>  -­‐2  
Enter  Integer  3>  3  
Enter  Integer  4>  102  
Enter  Integer  5>  -­‐7  
Enter  Integer  6>  50  
Enter  Integer  7>  11  
Enter  Integer  8>  23  
Enter  Integer  9>  -­‐13  
Enter  Integer  10>  99  
 
Among  the  inputs,  -­‐13  is  the  minimum  while  102  is  the  maximum.  
 
2) Ask  the  user  for  10  integers  as  input.  Store  the  inputs  in  an  array  of  size  10.  
Afterwards,  ask  the  user  to  input  an  integer.  Your  program  must  search  if  the  
last  integer  input  exists  in  the  array  and  must  remove  its  every  occurrence.    
Afterwards,  shift  each  element  following  the  integer  “to  the  left”  (i.e.  to  a  lower  
index).  Next,  fill  the  indices  near  the  end  of  the  array  (i.e.  those  “vacated”  due  to  
the  shift)  with  zeroes.  Finally,  display  the  resulting  array.  If  the  integer  to  be  
removed  does  not  occur  in  the  array,  display  a  message  instead  stating  that  the  
value  was  not  found  in  the  array.  
 
Sample  Run  1:  
 
Enter  Integer  1>  50  
Enter  Integer  2>  -­‐2  
Enter  Integer  3>  3  
Enter  Integer  4>  102  
Enter  Integer  5>  -­‐7  
Enter  Integer  6>  50  
Enter  Integer  7>  11  
Enter  Integer  8>  23  
Enter  Integer  9>  -­‐13  
Enter  Integer  10>  99  
 
Enter  integer  to  be  removed  >  50  
 
After  removal  of  every  occurrence  of  50,  the  array  now  looks  like  this:  
-­‐2  3  102  -­‐7  11  23  -­‐13  99  0  0  
 
 
 
 
 
 
 
 
Sample  Run  2:  
 
Enter  Integer  1>  35  
Enter  Integer  2>  0  
Enter  Integer  3>  9  
Enter  Integer  4>  10  
Enter  Integer  5>  71  
Enter  Integer  6>  -­‐5  
Enter  Integer  7>  -­‐112  
Enter  Integer  8>  -­‐23  
Enter  Integer  9>  -­‐8  
Enter  Integer  10>  0  
 
Enter  integer  to  be  removed  >  23  
 
23  does  not  have  any  occurrence  in  the  array.  
 
 
3) Ask  the  user  for  a  string  input  (maximum  number  of  characters  is  100,  and  
assume  that  there  are  no  white  spaces).  Your  program  should  determine  if  the  
string  input  is  a  palindrome  or  not.  A  palindrome  is  a  word/string  that  is  spelled  
the  same  when  spelled  backwards.  For  this  exercise,  do  not  use  the  strrev  
function,  or  any  of  its  equivalents,  if  ever  it  is  available.  
 
Sample  Run  1:  
 
Enter  a  string>  abbcbba  
 
abbcbba  is  a  palindrome.  
 
 
Sample  Run  2:  
 
Enter  a  string>  palindrome  
 
palindrome  is  NOT  a  palindrome.  
 
 
4) Ask  the  user  for  a  string  input  representing  a  valid  Roman  numeral  between  1  
and  3,999,  inclusive.  Assume  that  the  Roman  numeral  input  is  valid.  You  are  then  
to  display  the  integer  equivalent  of  the  input.    Here  is  an  excerpt  from  
FactMonster  (http://www.factmonster.com/ipka/A0769547.html)  on  
determining  the  value  of  Roman  numerals:  
 
Roman  numerals  are  expressed  by  letters  of  the  alphabet:  
 
I=1  
V=5  
X=10  
L=50  
C=100  
D=500  
M=1000  
 
There  are  some  basic  principles  for  reading  and  writing  Roman  numerals:  
 
• A  letter  repeats  its  value  that  many  times  (XXX  =  30,  CC  =  200,  etc.).  A  
letter  can  only  be  repeated  three  times,  and  is  only  applicable  to  powers  
of  10  (I,  X,  C,  M).  
• If  one  or  more  letters  are  placed  after  another  letter  of  greater  value,  add  
that  amount.    
VI  =  6  (5  +  1  =  6)  
LXX  =  70  (50  +  10  +  10  =  70)  
MCC  =  1200  (1000  +  100  +  100  =  1200)  
• If  a  letter  is  placed  before  another  letter  of  greater  value,  subtract  that  
amount.  
IV  =  4  (5  –  1  =  4)  
XC  =  90  (100  –  10  =  90)  
CM  =  900  (1000  –  100  =  900)  
 
Several  rules  apply  for  subtracting  amounts  from  Roman  numerals:  
o Only  subtract  powers  of  ten  (I,  X,  or  C,  but  not  V  or  L)  

For  95,  do  NOT  write  VC  (100  –  5).  DO  write  XCV  (XC  +  V  or  90  +  
5)  

o Only  subtract  one  number  from  another.  


 
For  13,  do  NOT  write  IIXV  (15  –  1  -­‐  1).  DO  write  XIII  (X  +  I  +  I  +  I  
or  10  +  3)  
 
o Do  not  subtract  a  number  from  one  that  is  more  than  10  times  
greater  (that  is,  you  can  subtract  1  from  10  [IX]  but  not  1  from  
20—there  is  no  such  number  as  IXX.)  
 
For  99,  do  NOT  write  IC  (C  –  I  or  100  -­‐  1).  DO  write  XCIX  (XC  +  IX  
or  90  +  9)  

Sample  Run  1:  

Enter  a  Roman  numeral  between  1  and  3,999>  MCMXLVIII  


 
MCMXLVIII  has  the  numerical  equivalent  of  1948  
 

Sample  Run  2:  

Enter  a  Roman  numeral  between  1  and  3,999>  MMDCCCLXXXIV  


 
MMDCCCLXXXIV  has  the  numerical  equivalent  of  2884  
 

Sample  Run  3:  

Enter  a  Roman  numeral  between  1  and  3,999>  MMMDCCCLXXXVIII  


 
MMMDCCCLXXXVIII  has  the  numerical  equivalent  of  3888  

You might also like