
MAJU|ComputerProgrammingCS1123|Spring2012|Assignment#41
COMPUTER PROGRAMMING (CS1123) SPRING 2012
ASSIGNMENT # 4
SUBMISSION DATE: 30-03-2012 SUBMISSION TIME: 6 PM
NOTE:Carefullyreadinstructionsgivenattheendofassignmentbeforesolvingit.
1. Declareanintegerarrayofsize20.Askusertoentervaluesinthearray.Yourtaskisto
swaptheoddindexeswiththeevenindexes(nexttoeachoddindexistheevenindex
whichhavetobeswapped),youhavetoleave0thindexand19thindexasitis.After
swapping,displaytheswappedarray.
2. Declareintegeranarrayofsize10.Askusertoentervaluesinthearray.Yourtaskisto
displaythenumberofdistinctdigitsinthearray.Exampleisgivenbelow:
Digit Count
4 3
2 5
10 2
3. Declaretwointegerarraysofsizes14each.Yourtaskistodisplaytheelementswhichare
commoninbotharrays.
4. Declaretwointegerarraysofsizes8each.Inputvaluesinarrays.Askusertoenter
choice.Ifuserenters‘1’,theprogramwilldisplayallthoseelementswhicharepresent
inthefirstarraybuttheyarenotpresentinthesecondarray.Ifchoiceis‘2’,the
programwilldisplayallthoseelementswhicharepresentinthesecondarraybutthey
arenotpresentinthefirstarray.
5. DeclareanarrayA[]ofsize6andanarrayB[]ofsize12.Yourtaskistodetermine
whetheralltheelementsofA[]arepresentinB[]ornot.
6. Writeaprograminwhichyouhaveacharacterarrayofsize20.Inputarrayfromthe
user.Asktheusertoenterstartingindexandthenumbersofcharacters.Thenprintthe
arrayfromtheindexgivenbytheuserconsideringthenumberofcharactersuserwants
toprint.Inputcancontainspaces.
7. Declareacharacterarrayofsizeofsize20.Inputcharacterarrayfromuser.Takea
characterfromtheuseranddisplaythelocation(s)ofthatcharacterinthearray.
8. Declareacharacterarrayofsizeofsize20.Inputthecharacterarrayfromtheuser.
Countthetotalnumberofcharactersstoredinthearray.Displaytheresult.