2021 22
2021 22
Q. 2 Give the 16-bit signed (2’s complement) representation of the following decimal
numbers, and convert to hexadecimal:
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
Sign bit
140ooo|0| IO 100 Oop ooo0 o000 000
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
G3
ZZnpt N
No
Yet . lo
ev raV*10tr
t t/p
(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
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. 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;
}
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;
}
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;
}
return 0;
}
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];
2
Q3)
#include <stdio.h>
int main()
{
int i, j, N;
printf("Enter N: ");
scanf("%d", &N);
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
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
1
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS DUBAI
INTERNATIONAL ACADEMIC CITY, DUBAI
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] ) ;
}
int main( )
{
f loat basic,HRA,DA,EPF,total;
printf ( " Enter the basic salary\ n" ) ;
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;
}
return 0;
}
void main()
{
int noterms;
float sum;
printf("\nEnter number of terms:");
scanf("%d", ¬erms);
sum = Sum_Of_Series(noterms);
printf("\n Sum of given series is: %f", sum);
}
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.
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” )
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
2
BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS
DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI
FIRST SEMESTER 2020 – 2021
DEPARTMENT OF COMPUTER SCIENCE
SECTION 3
Q1. 3+2
Convert -25.50 to IEEE754 single precision floating point format. Include all
the steps in your solution.
110000011 10011000000000000000000
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” )
#include<stdio.h>
int main()
{
1
if ( fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL )
printf("ERROR...");
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);
}