0% found this document useful (0 votes)
11 views24 pages

2021 22

The document outlines the structure and content of computer programming tests and examinations for the first semester of 2021-2022 at the Birla Institute of Technology & Science, Pilani, Dubai Campus. It includes various programming tasks, questions on floating point representation, matrix manipulation, and output predictions for C programs. Additionally, it specifies the weightage, duration, and guidelines for students to follow during the assessments.

Uploaded by

mailsachiii001
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)
11 views24 pages

2021 22

The document outlines the structure and content of computer programming tests and examinations for the first semester of 2021-2022 at the Birla Institute of Technology & Science, Pilani, Dubai Campus. It includes various programming tasks, questions on floating point representation, matrix manipulation, and output predictions for C programs. Additionally, it specifies the weightage, duration, and guidelines for students to follow during the assessments.

Uploaded by

mailsachiii001
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
You are on page 1/ 24

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS

DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI


FIRST SEMESTER 2021 – 2022
DEPARTMENT OF COMPUTER SCIENCE

COURSE : Computer Programming(CS F111)


COMPONENT : Test 1 (Closed Book) WEIGHTAGE : 20% (40 Marks)
DATE : 02-Oct-2021 (2:30 pm) DURATION : 50 Minutes

Note: Please read the questions clearly before attempting.


Write down any assumptions that you make.
Show your work in steps.
Associativity and precedence table, ASCII table attached on the last page.

Q.1 Attempt the following questions: 3*2=6

A Convert (-123.03125)10 to IEEE754 single precision floating point format. Include


all the steps in your solution.
B Convert the following IEEE754 single precision floating point representation into
decimal number.
0 1000 0101 101 0011 0100 0000 0000 0000

Q. 2 Give the 16-bit signed (2’s complement) representation of the following decimal
numbers, and convert to hexadecimal:

A -1234 567 2*2=4


b

Q. 3 Draw a flowchart to check whether the given number is palindrome or not. 4


(A palindrome number remains the same when reversed. e.g. 737 )

Q. 4 Perform the following conversions. (Assume unsigned nos) 3*2=6


a. (1100000110001100)2 = ( )8 = ( )16 = ( )10
b. (AA.BB)16 = ( )2 = ( )8 = ( )10

Q. 5 What is the output of the following programs on expression solving. Output may also 2*10=20
contain error, runtime error and compilation error. Please specify clearly?

a #include<stdio.h>
int main()
{
int a=10;
a = (17, 19, 21);
printf("%d", a);
return 0;
}
1
b #include<stdio.h>
int main()
{
int x = 5;
(x & 4) ? printf("true") : printf("false");
return 0;
}
c. #include<stdio.h>
int main()
{
int a = 8, b = 1, c = 2;
printf("a|b&c = %d\n", a|b&c);
return 0;
}
d. #include<stdio.h>
int main()
{
int i = 12;
i++;
i * i * i;
printf("%d\n",i);
return 0;
}
e. #include<stdio.h>
#define FALSE -1
#define NULL 0
#define TRUE 2

int main(){
if(NULL)
printf("NULL");
else if(FALSE)
printf("TRUE");
else
printf("FALSE");
return 0;
}
f. #include<stdio.h>
int main(){
int i = 1, j = 1;
if(i++ == j++)
printf("%d %d", i--, j--);
else
printf("%d %d", i, j);
return 0;
}
g. #include<stdio.h>
int main()
{
if(printf("0"))
printf("inside if block");

2
else
printf("inside else block");
return 0;
}
h. #include<stdio.h>
int main(){
int i = 8, j = 9;
if(!printf(""))
printf("%d %d", i, j);
else
printf("%d %d", i++, ++j);
return 0;
}
i. #include<stdio.h>
int main()
{
int i = 6;
int a = --i + --i + --i;
printf("%d",a);
return 0;
}
j. #include<stdio.h>
int main()
{
int i = 7;
int a = --i - --i - --i - --i;
printf("%d",a);
return 0;
}
Associativity and Precedence table

ASCII table

3
******** END ********

4
G. 4-123. 0325

O:-123.03125) -11D11.0000

- 1 -1 1110110000I X2

Biased eponent= o+127 13.3


133 10000)O)

Sign bit
140ooo|0| IO 100 Oop ooo0 o000 000

bb . 0 00D 0)0) 10 001) 0)00 00o0 0000 000o

33
Atnal Exponent 133-127 6
anhssA j0100)0)
O.101001) 0l) :(6. 65b 390b2s)
X C-Dx (1+0 65039062s)x
4oS 625
a). 1 2 34

2'sC-1234) = 1 l o n ool0 1110 =(FB-2E


b. 567

's (sb7) cood 0010 o01o1 - C0237)

G3
ZZnpt N

No

Yet . lo
ev raV*10tr
t t/p

Pnnt / CNot Palidna"


Rlidrome

(STOP
O)C11 0000DlID00 llo(14061 =(95)
AA.BB) (10101D 1o.1011o11),-(170.7304687s)
Q5 Solutions
a) 21

b) True

c) 8

d) 13

e) True

f) 2 2

g) 8 9
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI
FIRST SEMESTER 2021 – 2022
DEPARTMENT OF COMPUTER SCIENCE

COURSE : Computer Programming(CS F111)


COMPONENT : Test 2 (Open Book) WEIGHTAGE : 20% (40 Marks)
DATE : 06-Nov-2021 (2:30 – 03:20PM) DURATION : 50 Minutes

Note: Please read the questions clearly before attempting.


Write down any assumptions that you make.
Show your work in steps. Associativity and precedence table, ASCII table attached on the last page.

Q. 1 Write a C program to get input from the user for a 5x5 matrix and check sum of 6M
middle row is equal to sum of middle column.

Q. 2 Write a C program to get input from the user for a 5x5 matrix and replace the 6M
diagonal (top left to bottom right) elements with zero.

Q. 3 Write a C program to print the following pattern. 6M


54321
4321
321
21
1

Q. 4 What is the output of the following programs on expression solving. Output may also 3*7=21M
contain error, runtime error and compilation error. Please specify clearly?
a #include <stdio.h>

int main()
{
int x, y, z;
x = y = z = 2;
z = ++x || ++y;
printf ("x = %d y = %d z = %d\n", x, y, z);
return 0;
}

X=3, Y=2, Z=1


b #include <stdio.h>

int main()
{
int x, y, z;
x = y = z = -2;
1
z = x++ && ++y;
printf ("x = %d y = %d z = %d\n”, x, y, z);
return 0;
}

X=-1, Y=-1, Z=1


c. #include <stdio.h>
int main()
{
int x = 5, y, z;
z=y=x;
z *= y = x * x;
printf ("x = %'d y = %d z = %d", x, y, z);
return 0;
}

X=5, Y=25, Z=125

d. #include <stdio.h>
int main()
{
int x = 5, z;
z = x++ + x++;
printf ("x = %d z = %d", x, z);
return 0;
}

X=7, Z=11
e. #include <stdio.h>
int main()
{
int i = 1, j = 1 ;
for (;j;)
{
j = i++ <8 ;
printf ("%d%d\n",i, j);
}
return 0;
}

21
31
41
51
61
71
81
90

f. #include <stdio.h>
int main()

2
{
int x = 5, y, z;
z=y=x;
z *= y /= (x-10);
printf ("x = %d y = %d z = %d", x, y, z);
return 0;
}

X=5, y=-1, z=-5


g. #include <stdio.h>
int main()
{
int x, y, z, i;
x=y=z=5;
i = ++x || ++y && ++z;
printf ("x = %d y = %d z = %d i=%d\n", x, y, z, i);

return 0;
}

X=6, y=5, z=5, i=1

******** END ********

3
Q1)
#include <stdio.h>
int main()
{
int a[5][5],i,j,k,s1=0,s2=0;
printf("Enter Elements for Matrix of Size 5*5:\n\n");
/*Reads the numbers or elements for 5*5 matrix*/
for(i=0;i<=4;i++)
for(j=0;j<=4;j++)
{
scanf("%d",&a[i][j]);
}
/* For printing the elements in matrix form*/
printf("\nMatrix is:\n\n");
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
/* To print and sum of middle row elements*/
printf("\nMiddle Row Elements: ");
for(k=0;k<=4;k++)
{
s1=s1+a[2][k];
printf("%d ",a[2][k]);
}
printf("\nSum of Middle Row Elements : %d\n",s1);
/* To print and sum of middle column elements*/
printf("\nMiddle Column Elements : ");
for(k=0;k<=4;k++)
{
s2=s2+a[k][2];
printf("%d ",a[k][2]);
}
printf("\nSum of Middle Column Elements : %d\n",s2);
/* Check the of middle row EQUALS to middle column */
if(s1==s2)
printf("\nSum is EQUAL");
else
printf("\nSum is NOT EQUAL");
return 0;
}

1
Q2)
#include<stdio.h>

int main()
{
int i,j,n;
float a[5][5];

printf("Enter Elements for Matrix of Size 5*5:\n\n");


/*Reads the numbers or elements for 5*5 matrix*/
for(i=0;i<=4;i++)
for(j=0;j<=4;j++)
{
scanf("%d",&a[i][j]);
}
/*Replace diagonal by 0*/
for(i=0;i< n;i++)
{
for(j=0;j< n;j++)
{
if(i==j)
{
a[i][j] = 0;
}
}
}
/* For printing the elements in matrix form*/
printf("\nChanged Matrix is:\n\n");
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}

2
Q3)
#include <stdio.h>

int main()
{
int i, j, N;

printf("Enter N: ");
scanf("%d", &N);

for(i=N; i>=1; i--)


{
// Logic to print numbers
for(j=i; j>=1; j--)
{
printf("%d", j);
}

printf("\n");
}

return 0;
}

3
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI
FIRST SEMESTER 2021 – 2022 Questions: 5
DEPARTMENT OF COMPUTER SCIENCE Pages: 1

COURSE : Computer Programming(CS F111)


COMPONENT : Compre examination (Closed Book) WEIGHTAGE : (25 Marks)
DATE : 05-Jan-2022 (8:30 – 9:30AM) DURATION : 60 Minutes

Note: Please read the questions clearly before attempting. Write down any assumptions that you make.
Show your work in steps.

Q. 1 BITS Pilani Dubai wants to develop a frequency distribution for the given marks of 5M
students obtained in the compre examination. Assuming the data contains 100
positive integers in the range of 1 to 50, write a function to print the number of times
each integer marks occurs in the data.

Q. 2 BITS Pilani wants to develop a software to calculate total salary for each employee. 5M
If the Basic Salary(basic) is less than or equal to 10000 then HRA = 10% of the
basic, DA = 31% of the basic and Employee provident fund is 12% of the basic +
DA. If the basic Salary is less than or equal to 20000 then HRA = 20% and DA =
35% of the basic and Employee provident fund is 12% of the basic + DA. If the
basic Salary is greater than 20000 then HRA = 24% and DA = 50% of the basic and
Employee provident fund (EPF) is 12% of the basic + DA.

WACP to find the total salary of an employee and it should handle all the
conditions. Formula to compute the total salary is Basic + HRA+DA+EPF.

Q. 3 1 1 1 1 5M
WAC function to find Sum of series 1 + 22 + 32 + 42 + 52 using functions. Please
insert the code in this structure.
float Sum_Of_Series(int Num)

Return 0;

𝟏 𝟏 𝟏 𝟏
Q. 4 WACP to Find Sum of series 𝟏 + 𝟐𝟐 + 𝟑𝟐 + 𝟒𝟐 + 𝟓𝟐 using while Loop. 5M

Q. 5 WACP to print the following output for the given input using pointers. 5M
Input: HAPPY NEW YEAR
Output: RAEY WEN YPPAH

******** END ********

1
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS DUBAI
INTERNATIONAL ACADEMIC CITY, DUBAI

FIRST SEMESTER 2021 – 2022

DEPARTMENT OF COMPUTER SCIENCE

Comprehensive Examination - Part A Solutions

Q 1) # include < stdio. h>

void main( )
{
int mark s;
int f req [ 5 1] = {0};
int i;
f or( i= 0; i< 100; i+ + )
{
printf ( " Enter mark s% d in the rang e[ 1-5 0] : " ,i+ 1) ;
scanf ( " % d" , &mark s) ;
f req [ mark s] + + ;
}
printf ( " \ nMark s\ tFreq uency" ) ;
f or( i= 1; i< = 5 0; i+ + )
printf ( " \ n% d\ t% d" ,i,f req [ i] ) ;
}

Q 2) # include < stdio. h>

int main( )
{
f loat basic,HRA,DA,EPF,total;
printf ( " Enter the basic salary\ n" ) ;

scanf ( " % f " ,&basic) ;

if ( basic< = 10000)
{
DA= basic* 0. 3 1;
HRA= 0. 10* basic;
EPF= 0. 12* ( basic+ DA) ;
total= basic+ DA+ HRA+ EPF;
}
else if (basic>10000 && basic<=20000)
{
DA=basic*0.35;
HRA=0.20*basic;
EPF=0.12*(basic+DA);
total=basic+DA+HRA+EPF;
}
else //(basic<=20000)
{
DA=basic*0.50;
HRA=0.24*basic;
EPF=0.12*(basic+DA);
total=basic+DA+HRA+EPF;
}

printf("BASIC of the Employee is %f\n",basic);


printf("HRA of the Employee is %f\n",HRA);
printf("DA of the Employee is %f\n",DA);
printf("EPF of the Employee is %f\n",EPF);
printf("TOTAL Salary of the Employee is %f\n",total);

return 0;
}

Q3) #include <stdio.h>

float Sum_Of_Series(int num)


{
int i;
float term,sum= 0;
for(i= 1;i<=num;i++)
{
term = 1.0/(i*i);
sum = sum + term;
}
return sum;
}

void main()
{
int noterms;
float sum;
printf("\nEnter number of terms:");
scanf("%d", &noterms);
sum = Sum_Of_Series(noterms);
printf("\n Sum of given series is: %f", sum);
}

Q4) #include <stdio.h>


void main()
{
int i;
float term,sum= 0;
int noterms;
printf("\nEnter number of terms:");
scanf("%d", &noterms);
i=1;
while(i<=noterms)
{
term = 1.0/(i*i);
sum = sum + term;
i++;
}
printf("\n Sum of given series is: %f", sum);
}

Q5) #include <stdio.h>


#include <string.h>

// function definition of the revstr()


void revstr(char *str1)
{
// declare variable
int i, len, temp;
len = strlen(str1); // use strlen() to get the length of str string

// use for loop to iterate the string


for (i = 0; i < len/2; i++)
{
// temp variable use to temporary hold the string
temp = str1[i];
str1[i] = str1[len - i - 1];
str1[len - i - 1] = temp;
}
}
int main()
{
char str[50]; // size of char string
printf (" Enter the string: ");
gets(str); // use gets() function to take string

printf (" \n Before reversing the string: %s \n", str);

// call revstr() function


revstr(str);
printf (" After reversing the string: %s", str);
}
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI
FIRST SEMESTER 2020 – 2021 Questions: 3
DEPARTMENT OF COMPUTER SCIENCE Pages: 1

COURSE : Computer Programming(CS F111)


COMPONENT :Compre(Closed Book) PART-B Marks : 25 Marks
DATE : 05th JAN 2022 ( 09:40 – 10:40AM) DURATION : 60 Minutes

Note: Please read the questions clearly before attempting. Write down any assumptions that you make.
Show your work in steps. Associativity and precedence table, ASCII table attached on the last page.

Q1. 3+2M
a. Convert -25.50 to IEEE754 single precision floating point format. Include all
the steps in your solution.

b. Perform the following conversions. (Assume unsigned nos)


(100100011100)2 = ( )8 = ( )16 = ( )10

(45.25)8 = ( )2 = ( )16 = ( )10

Q. 2 Assume that there are four files namely ‘One.txt’, ‘Two.txt’, ‘Three.txt’ and 10M
‘Four.txt’. The content of each file is given below. Write a C program to
concatenate the strings of the ‘One.txt’ and ‘Three.txt’ and store the result in a
new file ‘Five.txt’. Similarly concatenate the strings of the ‘Four.txt’ and
‘Two.txt’ and store the result in a new file ‘Six.txt’ (Output in the ‘Five.txt’
should contain: “ STAY STAY” and Output in the ‘Six.txt’ should contain “
SAFE HOME” )

File Name Content


One.txt STAY
Two.txt HOME
Three.txt STAY
Four.txt SAFE

Q3. Consider a Book is described using Book_ID, Title, Author, Subject. Write a 10M
C program to create two structure variables Book1, Book2 initialize its
members. Pass structure as a function argument to print Book1 and Book2
details.

1
ASCII table

******** ALL THE BEST ********

2
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI
FIRST SEMESTER 2020 – 2021
DEPARTMENT OF COMPUTER SCIENCE

COURSE : Computer Programming(CS F111)


COMPONENT :Compre(Closed Book) Part-B Marks : 25 Marks
DATE : 05th JAN 2022 DURATION : 60 Minutes

Note: Please read the questions clearly before attempting.


Write down any assumptions that you make.
Show your work in steps

SECTION 3

Q1. 3+2
Convert -25.50 to IEEE754 single precision floating point format. Include all
the steps in your solution.
110000011 10011000000000000000000

Perform the following conversions. (Assume unsigned nos)


(100100011100)2 = (4434 )8 = ( 91C )16 = ( 2332)10

(45.25)8 = ( 100101.010101)2 = ( 25.54 )16 = ( 37.328125 )10

Q. 2 10
Assume that there are four files namely ‘One.txt’, ‘Two.txt’, ‘Three.txt’ and
‘Four.txt’. The content of each file is given below. Write a C program to
concatenate the strings of the ‘One.txt’ and ‘Three.txt’ and store the result in
a new file ‘Five.txt’. Similarly concatenate the strings of the ‘Four.txt’ and
‘Two.txt’ and store the result in a new file ‘Six.txt’ (Output in the ‘Five.txt’
should contain: “ STAY STAY” and Output in the ‘Six.txt’ should contain “
SAFE HOME” )

File Name Content


One.txt STAY
Two.txt HOME
Three.txt STAY
Four.txt SAFE

#include<stdio.h>
int main()
{

FILE *fp1, *fp2, *fp3, *fp4, *fp5, *fp6;


char ch;
fp1 = fopen("one.txt", "r");
fp2 = fopen("two.txt", "r");
fp3 = fopen("three.txt", "r");
fp4 = fopen("four.txt", "r");

1
if ( fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL )
printf("ERROR...");

fp5 = fopen("Five.txt", "w");


while((ch = fgetc(fp1)) != EOF)
fputc(ch, fp5);

while((ch = fgetc(fp3)) != EOF)


fputc(ch, fp5);
fp6 = fopen("Six.txt", "w");
while((ch = fgetc(fp4)) != EOF)
fputc(ch, fp6);

while((ch = fgetc(fp2)) != EOF)


fputc(ch, fp6);

fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
fclose(fp5);
fclose(fp6);
return 0;
}

Q3. Consider a Book is described using Book_ID, Title, Author, Subject. Write a 10
C program to create two structure variables Book1, Book2 initialize its
members. Pass structure as a function argument to print Book1 and Book2
details.

#include <stdio.h>
#include <string.h>
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
};
/* function declaration * /
void printBook( struct Books book );
int main( )
{
struct Books Book1; /* Declare Book1 of type Book * /
struct Books Book2; /* Declare Book2 of type Book * /
/* book 1 specification * /
strcpy( Book1.title, "C Program m ing");
strcpy( Book1.author, "Nuha Ali");
strcpy( Book1.subject, "C Program m ing Tutorial");
Book1.book_id = 6495407;
/* book 2 specification * /
2
strcpy( Book2.title, "Telecom Billing");
strcpy( Book2.author, "Zara Ali");
strcpy( Book2.subject, "Telecom Billing Tutorial");
Book2.book_id = 6495700;
/* print Book1 info * /
printBook( Book1 );
/* Print Book2 info * /
printBook( Book2 );
return 0;
}
void printBook( struct Books book )
{
printf( "Book title : %s\n", book.title);
printf( "Book author : %s\n", book.author);
printf( "Book subject : %s\n", book.subject);
printf( "Book book_id : %d\n", book.book_id);
}

You might also like