Docsity

CS1123 Computer Programming Assignment 4 - Spring 2012, Exercises of Computer Engineering and Programming

Toggle sidebar
bg1
 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.
docsity.com
pf2

Partial preview of the text

Download CS1123 Computer Programming Assignment 4 - Spring 2012 and more Exercises Computer Engineering and Programming in PDF only on Docsity!

MAJU | Computer Programming CS1123 |Spring 2012| Assignment # 4 1

C O M P U T E R P R O G R A M M I N G ( C S 1 1 2 3 ) S P R I N G 2 0 1 2

A S S I G N M E N T # 4

SUBMISSION DATE: 30-03-2012 SUBMISSION TIME: 6 PM

NOTE: Carefully read instructions given at the end of assignment before solving it.

  1. Declare an integer array of size 20. Ask user to enter values in the array. Your task is to swap the odd indexes with the even indexes (next to each odd index is the even index which have to be swapped), you have to leave 0 th^ index and 19 th^ index as it is. After swapping, display the swapped array.
  2. Declare integer an array of size 10. Ask user to enter values in the array. Your task is to display the number of distinct digits in the array. Example is given below: Digit Count 4 3 2 5 10 2
  3. Declare two integer arrays of sizes 14 each. Your task is to display the elements which are common in both arrays.
  4. Declare two integer arrays of sizes 8 each. Input values in arrays. Ask user to enter choice. If user enters ‘1’, the program will display all those elements which are present in the first array but they are not present in the second array. If choice is ‘2’, the program will display all those elements which are present in the second array but they are not present in the first array.
  5. Declare an array A[ ] of size 6 and an array B[ ] of size 12. Your task is to determine whether all the elements of A[ ] are present in B[ ] or not.
  6. Write a program in which you have a character array of size 20. Input array from the user. Ask the user to enter starting index and the numbers of characters. Then print the array from the index given by the user considering the number of characters user wants to print. Input can contain spaces.
  7. Declare a character array of size of size 20. Input character array from user. Take a character from the user and display the location(s) of that character in the array.
  8. Declare a character array of size of size 20. Input the character array from the user. Count the total number of characters stored in the array. Display the result.

docsity.com

MAJU | Computer Programming CS1123 |Spring 2012| Assignment # 4 2

  1. Write a program that takes a character array of size 25 from user and prints the number of small letters, capital letters, numbers and special characters in the array. Hint: Use ASCII codes table provided in question 1.
  2. Write a program that takes a string of characters (in character array) from the user (assuming there are no white spaces entered) and then tells the user if the string entered is a palindrome or not. Take array size = 15.
  3. Write a program which will initialize a character array of size 10 from user input. Count the number of spaces in the array and display the result.

IMPORTANT INSTRUCTIONS:

  1. Read the problem carefully.
  2. For submission make a folder named your name and reg. no. for example amjad_bc013051 , paste all programs in it. File names of programs must be according to the question numbers.
  3. Submission date and time is fixed; it will not be extended in any case.
  4. Honest attempt of solving the assignment will be appreciated, therefore try to solve the assignment rather than copying it from your fellows.
  5. No compensation for copy cases and plagiarism. Strictly F grade will be awarded.

‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐GOOD LUCK ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐

docsity.com