You are on page 1of 4

REG.

NO

* *

MANIPAL INSTITUTE OF TECHNOLOGY


(Constituent Institute of Manipal University)
MANIPAL-576104

FIRST SEMESTER B.Tech DEGREE 1st SESSIONAL EXAMINATION


SUBJECT: CSE-1001 PROBLEM SOLVING USING COMPUTERS (PSUC)
TIME: 1 HOUR
12-09- 2015; 1:45 PM 2:45 PM
MAX. MARKS: 15
Instructions to Candidates
Answer ALL Three full questions in ORDER
Indicate all the steps where ever necessary.
Do not seek any clarification from invigilator.

[For programming questions any other logic which gives the CORRECT &
REQUIRED output may be considered for awarding marks]
I.

(a) What will be the output when following error free C++ code is executed?
void main(){
a) ..1..0
int i = 1;
b) 0..1..
do{
c) 0..1..0..1..
cout<<i<<"..";
d) 1..0.. [ANS]
} while(i--);
}
(b) In C++, the operator << is used for
a) Bitwise double shifting
b) Bitwise left shifting [ANS]
c) Bitwise cin
d) Bitwise compliment.
(c) What will be the output when following error free C++ code is executed?
void main( ){
int z, x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;
cout<<z;
}
a) 10 [ANS]
b) 11
c) 0
d) 1
(d) Assuming an int is two bytes long, what will be printed by error free C++ code below?
void main(){
a) 10
int array[10]={1,2,3,4,5};
b) 15
cout<<sizeof(array);
c) 16
}
d) 20 [ANS]
(e) What will be the output when following error free C++ code is executed?
void main(){
1 [ANS]
0
a.
c.
int k = 0, x = 1;
x=1
x=2
while (k < 25){
if (k % 5 == 0){
1
1
x += k;
b.
d.
x=0
x=1
cout<< x; }
else
break;
++k;}
cout<<"\nx="<< x + k;}
(1 mark * 5)

CSE-1002

Page 1 of 4

II. (a) Write down an algorithm to find and print the largest of N (N>0) numbers without using Arrays.
Name of algorithm: Print largest of N numbers
Step 1: Start
Step 2: Input N, X
Step 3: Max
X
Step 4: Counter
1
Step 5: While (Counter < N)
Begin
Counter
Counter + 1
Input X
If (X > Max) then
Max
X
End
Step 6: Print Max
Step 7: Stop
(Evaluation: No Logic 0.5; Partial Logic 1; Full Logic 2)
(b) What would be the value of i after evaluating the following expression (clearly show each
operation with its value)
i= 2 * 3/ 4+ 4 / 4 + 8 2 + 5 / 8
Ans:
Stepwise evaluation of this expression is shown below:
i=2*3/4+4/4+8-2+5/8
i=6/4+4/4+8-2+5/8
operation: *
i=1+4/4+8-2+5/8
operation: /
i = 1 + 1+ 8 - 2 + 5 / 8
operation: /
i=1+1+8-2+0
operation: /
i=2+8-2+0
operation: +
i = 10 - 2 + 0
operation: +
i=8+0
operation: i=8
operation: +

( marks for 4 operations each; no operations shown, only output marks)


(c) Distinguish between (any 2 differences)
(i) Compiler and Interpreter

CSE-1002

Page 2 of 4

(ii) Cache and Primary memory

( marks for each correct difference)


(2 + 1 + 2 marks)
III. (a) Write a C++ program to find factorial of a number using for loop. Explain the working of for loop
with respect to the program.
void main( ) {
int i, num, fact=1;
cout<<"Enter the number:";
cin>>num;
for (i=1; i<=num; i++)
for loop statement
fact=fact*i;
Body of the loop
cout<<"\nFactorial of "<<num<<"
statement after loop
is "<< fact;
}
Illustration:

1. The initialization of the loop control variable i=1; is done using assignment
statement.
2. The value of the control variable i is tested using the test condition i<num.
3. If condition i<num is true body of the loop is executed; otherwise loop is
terminated and execution continues with the statement that immediately follows the
loop.
4. When the body of the loop is executed, control is transferred back to the for
statement after evaluating the last statement in the loop. The control variable i is
incremented and new value of control variable is tested to see whether it satisfies the
loop condition i<num. If the condition i<num is satisfied body of the loop is again
evaluated. The process continues until the test condition becomes false.
(Correct factorial code using for loop 1 mark & illustration of for loop- 1 mark)
(b) Implement a C++ program to read n elements into an integer array and display the number of
prime elements.
void main (){
//Prime checking
int a[100], i, j, n, count=0,flag;
for(i=0;i<n;i++){
cout<<"Enter the array limit: ";
flag=0;
cin>>n;
for(j=2;j<a[i]/2;j++){
cout<<"\nenter n elements.\n";
if(a[i]%j==0){
for(i=0;i<n;i++)
flag=1;
cin>>a[i];
break;
//Display (Optional)
}
cout<<"\nNumbers entered are:\n";
}
for(i=0;i<n;i++)
if(flag==0 && a[i]!=1){
cout<<a[i]<<endl;
count++;

CSE-1002

Page 3 of 4

cout<<("\n The prime numbers in the


array are :-\n");//(optional statement)

cout<<a[i]<<"\t"; //displays the


prime numbers (optional statement)
}
}
cout<<"The number of prime elements in
the array is:"<<count;
}
(Reading limit value n and array elements- marks; prime checking- 1 mark;
computing count and displaying- marks)

(c) Write the value in k after executing the following error free code.
int k, num = 3 ;
k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : ( num >10? 400:500) ) ;
Ans:
Value of k=500

(2 + 2 + 1 marks)
ALL THE BEST

CSE-1002

Page 4 of 4

You might also like