0% found this document useful (0 votes)
26 views2 pages

Section 8: Part A: Tutorial Problems For Practice

This document provides instructions for students to complete problems as part of a lab assignment. It includes 3 tutorial problems to practice drawing flowcharts and algorithms and 3 programming assignment problems. For the tutorial problems, students are asked to write programs to: 1) Convert integers to their 8-bit 2's complement representations, 2) Determine the output of a given C program, 3) Determine the output of another given C program. For the programming assignment, students are asked to write programs to: 1) Read a binary array and print its decimal value, 2) Read an array and print the longest run of 1s, 3) Read a polynomial's coefficients, compute it for a given x value using nested brackets. Students are instructed to name

Uploaded by

Sohini Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Section 8: Part A: Tutorial Problems For Practice

This document provides instructions for students to complete problems as part of a lab assignment. It includes 3 tutorial problems to practice drawing flowcharts and algorithms and 3 programming assignment problems. For the tutorial problems, students are asked to write programs to: 1) Convert integers to their 8-bit 2's complement representations, 2) Determine the output of a given C program, 3) Determine the output of another given C program. For the programming assignment, students are asked to write programs to: 1) Read a binary array and print its decimal value, 2) Read an array and print the longest run of 1s, 3) Read a polynomial's coefficients, compute it for a given x value using nested brackets. Students are instructed to name

Uploaded by

Sohini Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Section 8

PDS Lab Lab-4 01.09.2016


 

Part‐A: Tutorial Problems for Practice 

Instructions:
 Draw flowchart and or algorithm depicting how to solve each problem in this part.
 Submit your work latest by today. Please clearly write your name, roll number and mobile
number on the front page of the sheets.
 Create a sub directory named as LabT4 under your home directory.
 Give the name of the programs as <R> <T>1.c, <R> <T>2.c, .. etc. for the tutorial problems
problem 1, 2….., respectively. Here <R> implies your Registration No.
 Store all the programs under this tutorial part in the directory LabT4

1.  Write the 8‐bit 2's complement representations of the following integers:  

a. 123  

b. ‐123  

c. ‐7  

d. 63  

2. What is the output printed by the following program? 

#include<stdio.h>
void main(){
int A[]={0,1,2,3,4,5,6,7};
int n=8, step = 2, i, j, k, l, temp;
for(i=0;i<n-step;i++){
for(j=i;j<i+step;j++){
temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;}
step = (step*2)- 1;}
for(i=0; i<n; i++)printf(“%d “,A[i]);
}
 

[Hint: First try to have the answer of your own and then verify your answer by writing
appropriate programs for each statement.]
3. What is the output of the following program? 

main()
{
int a[5] = { 5, 1, 15, 20, 25 };
int i, j, k;
i = ++a[1] ;
j = a[1]++ ;
k = a[i++] ;
printf ("%d,%d,%d", i, j, k);
}

[Hint: First try to have the answer of your own and then verify your answer by writing
appropriate programs for each statement.]

Part‐B: Assignment Problems 

Instructions:
 Create a sub directory named as LabA4.
 Give the name of the programs as <R> <A2>1.c, <R> <A2>2.c, …, etc. for the tutorial
problems 1, 2….., respectively. Here <R> implies your Registration No.
 Store all the programs under this tutorial part in the directory LabA4.
 You should upload your programs to the Moodle course web page. Preferably in ZIP form
latest by 12:45 hrs. today only.
 
1. Write a program to read an integer 1D array containing 8 bits (0/1s) of an unsigned binary 
integer. The program should print the decimal value for the integer. 
 
2. Read a 1D array containing n elements (n input by user) containing only 0s and 1s. Print the 
length of the longest run of 1s. For example in the array 01011110011, the length is 4. 
 
3. A fast scheme for evaluating a polynomial such as:  , for a given value of 
(for  example)  is  to  arrange  the  computation  as  follows: 
 And  compute  the  result  from  the  innermost 
brackets  outwards.  Write  a  program  which  reads  the  order  of  the  polynomial  N,  the 
coefficients of the polynomial in ascending order of powers and then stores them in a 
float  array.  There  are  no  missing  terms  in  the  polynomial.  The  program  then  reads  a 
value  of  x,  and  computes  the  value  of  the  polynomial  for  that  x.  Use  the  fast  method 
described above. 
 
[Submit your solutions to Moodle course management system, latest by 12:45 hrs. toady.] 

You might also like