TA ZC163 EC-3R SOLTUION - Birla Institute of Technology...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Birla Institute of Technology & Science, Pilani Work-Integrated Learning Programmes Division Second Semester 2013-2014 EC-3 (Regular) Open Book Course No. : TA ZC163 Max Marks: 50 Course Title: Computer Programming Duration: 3 Hours --------------------------------------------------------------------------------------------------------------------- ----------------------- Q1) Answer the following questions: a) Consider the two binary numbers: A = 1011 1101, B = 1011 1111. For a machine with 8- bit processor, 2’s complement representation, if possible perform the following operations by clearly showing the steps. Otherwise give reason why operation can’t be performed. (i) A + B (ii) A – B Ans: (i) A+B 1011 1101 + 1011 1111 ____________ 0111 1100 Carry=1 It causes overflow, as carry into the msb(sign bit) and carry out of the msb are different. Therefore, this operation can not be performed. (ii) A-B= A+$(B) $(B)=2’s complement of B= 0100 0000 + 1 __________ 0100 0001 A-B is given as 1011 1101 + 0100 0001 ____________ 1111 1110 Thus, A-B= 1111 1110 b) In some programming language, if 7-bits are used to store a character, how many maximum characters can be represented? Ans: 2 7 =128 characters can be represented, if 7 bits are used to store a character.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
c) For a two-dimensional array arr[N][M], Write a single printf statement which prints the elements at four corners of matrix. Ans: printf(“%d %d %d %d”,arr[0][0],arr[0][M-1],arr[N-1][0],arr[N-1][M-1]); d) For a two-dimensional array arr[N][M], Write a for loop which multiplies each element of 3 rd column of matrix with 5. Ans: for(i=0;i<N;i++){ arr[i][2]*=5; } e) For a two-dimensional array arr[N][M], Assume that N and M are odd numbers and N=M. Write a for loop to swap the elements of middle row of the matrix with middle column (i.e middle row becomes middle column and vice versa) Ans: int i,temp; for(i=0;i<N;i++) { temp=arr[i][M/2]; arr[i][M/2]=arr[N/2][i]; arr[N/2][i]=temp; } [4+1+2+2+3=12M] Q2 Answer the following: a)
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern