E21 E22 E23 0756 CSE1021 Midterm
E21 E22 E23 0756 CSE1021 Midterm
:
Name :
Sub.
Q.No. Question Description Marks
Sec.
1 Write an algorithm, pseudo code and draw flow chart to perform sum of cubes of the
digits.
10
For example 123= 13+23+33=36
2 (a) The two algorithms below are both intended to calculate the sum of cubes from 1 to n,
where n is any positive integer.
Algorithm 1 Algorithm 2
i←n i←1
5
sum ← 0 sum ← 0
REPEAT n TIMES { REPEAT n TIMES {
sum← sum+(i * i*i) sum← sum + (i * i*i )
i←i-1} i←i+1}
Verify whether both algorithms calculate correct sum or not.
(b) What is the worst time complexity of the following code:
function(int n)
{
if (n==1)
return;
for (int i=1; i<=n; i++)
{ 5
for (int j=1; j<=n; j++)
{
printf("*");
break;
}
}
}
Show steps.
3 Write a python program to perform addition, subtraction, multiplication, integer
10
division and modulo division on two integer and float.
Page 1 of 2
4 Write individual algorithm to find out the square root of a number by using both in
10
built methods math.sqrt and math.pow.
5 Write a python program to check whether a given number is even or odd. If the
number is even, print number’s square and if number is odd print number’s cube.
10
For example if number is 2, it should be printed 22 i.e. 4, if number is 3 it should be
printed 33 i.e. 27.
Page 2 of 2