Mid2 - ITC - F14 - DONE
Mid2 - ITC - F14 - DONE
Serial No:
CS101
Sessional II
Introduction to Computing Total Time: 1 Hour
Monday, November 10, 2014 Total Marks: 75
Course Instructor
Dr. Sibt ul Hussain, Dr. Hassan Mujtaba, ________________
Ms. Uzma Marooof Signature of Invigilator
Page 1 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
float j = 9;
float k=10;
float l= j/k *(2/4)+ 30%4; 5
int m=l + 32.0/3.0+6;
int c, d=0;
d= c + d+1 ;
cout << m <<" "<<l<<endl;
cout << c <<" "<<d<<endl;
def funB(a):
print 'Hello',
c=funA(a) 5
return c + ' Students '
print c
a='xyz'
str='ITC'
z=funB(str)
print z
Output:
int main()
{
int x=-20;
while(x)
5
{
int j=0;
while(++j < 4);
cout<<" Hello "<<endl;
if(j==4);
else
cout<<" OK ";
x+=10;
}
}
Page 2 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
for(i; i ;)
{
j=0; 5
for (j; j < 5; ++j);
cout<< " * ";
cout<<endl;
i++;
}
cout<<("!");
j++;
}
cout<<endl;
i++;
}
Page 3 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
Q. No. 2
20
a) Write a Python function named minGap that accepts an integer list as a
parameter and returns the minimum 'gap' between adjacent values in the list. The gap
between two adjacent values in a list is defined as the second value minus the first value.
For example, suppose a variable called train is a list of integers that stores the following
sequence of values:
10
train = [1, 3, 6, 7, 12]
The first gap is 2 (3 - 1), the second gap is 3 (6 - 3), the third gap is 1 (7 - 6) and the fourth
gap is 5 (12 - 7). Thus, the call of minGap(train) should return 1 because that is the
smallest gap in the array. If you are passed a list with fewer than 2 elements, you should
return -1.
Page 4 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
b) Write a program (C++ or Python) that displays the following output on screen:
10
Page 5 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
Q. No. 3
Write a C++ program that accepts two integer inputs rows and cols and 15
outputs a comma separated grid of numbers where the first input (rows)
represents the number of rows of the grid and the second input (cols)
represents the number of columns. The numbers count up from 1 to (rows X cols).
Page 6 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
Q. No. 4
Suppose you are given two strings (they may be empty), s1 and s2. You 10
would like to "lace" these strings together, by successively alternating
elements of each string (starting with the first character of s1). If one string is
longer than the other, then the remaining elements of the longer string should simply be
added at the end of the new string. For example, if we lace 'abcd' and 'efghi', we would
get the new string: 'aebfcgdhi'
"""
# Your Code Here
Page 7 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
Page 8 of 8