Plus One Computer Science Chapter Wise previous Questions Chapter 7 Control Statements

Kerala Plus One Computer Science Chapter Wise Previous Questions Chapter 7 Control Statements

Question 1.
a) …………. statement takes the program control out of the loop even though the test expression is true. (March – 2015)
b) Consider the following code fragment. How many times will the character be printed on the screen?
for (1=0; i< 10; i =i+2);
cout <<“*”;
}
Answer:
a) break or goto
b) Only one time because of semicolon(;) in the end of the for (i=0; i<10; i=i+2);

Question 2.
Which selection statement tests the value of a variable or an expression against a list of integers or character constants? (Say – 2015)
a) For
b) If
c) Switch
d) Conditional expression
Answer:
c) switch

Question 3.
How many times the following loop will execute? (March – 2016)
int m = 2 do
{
cout<<“Welcome”; m++ ;
} while (m>10);
Answer:
Only one time

Question 4.
…………. search method is an example for the ‘divide and conquer method’. (Say – 2016)
Answer:
d) goto.

Question 5.
a) Name the type or loop which can be used to ensure that the body of the loop will surely be executed at least once. (March – 2017)
b) Consider the code given below and predict the output.
for (int i=1; i<=9; i=i+2)
{
if (i==5) continue;
cout<<i<< “
}
Answer:
a) do while loop(Exit controlled loop)
b) 1 3 7 9. It bypasses one iteration of the loop when i=5.

Question 6.
a) …………. is an entry control loop. (Say – 2015)
b) Explain the memory allocation for the following declaration statement.
int A[10] [10];
Answer:
a) while or for loop
b) To store an integer 4 bytes is used in Geany Editor
int A[10] [10]; → It needs 10*10*4 = 400 bytes7

Question 7.
Differentiate between break and continue statements in C++. (Say – 2016)
Answer:
break statement:- It is used to skip over a part of the code i.e. we can premature exit from a loop such as while, do-while, for or switch.
Syntax:
while (expression)
{
if (condition)
break;
}
continue statement :- It bypasses one iteration of the loop. That is it skips one iteration and continues the loop with the next iteration value.
Syntax :
while (expression)
{
if (condition)
continue;
}

Question 8.
Write C++ program forgetting the following output. (Say – 2016)
1
1 2
1 2 3
1 2 3 4
OR
Consider the following C++ program and answer the following questions.

#include<iostream.h>
int main()
{
int a, p=1;
for(a=1;a<=5;a+=2)
p = p*a;
cout<<p;
}

a) Predict the output of the above code.
b) Rewrite the above program using while loop.
Answer:

#include<iostream> 
using namespace std; 
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
cout<<j<<“\t”;
cout<<“\n”;
}
}
OR
a) The output is 15.
b) #include<iostream> 
using namespace std; 
int main()
{
int a=1,p=1; 
while(a<=5)
{
P=P*a;
a+=2;
}
cout<<p;
}

Question 9.
Write a program to do the following: (March – 2015)
a) Inputs the values for variables ‘n’ and ‘m’.
b) Prints the numbers between and ‘n’ which are exactly divisible by ‘m’.
c) Checks whether the numbers divisible by ‘m’ are odd or even.
OR
Write a program using nested loop that inputs a number ‘n’ which generates an output as follows. Hint: if the value of ‘n’ is 5, the output will be as ‘n’
25
25 16
25 16 9
25 16 9 4
25 16 9 4
Answer:

b) #include<iostream.h> 
#include<conio.h> 
void main()
{
clrscrO; int i,n,m;
cout<<“Enter values for n and m”;
cin>>n>>m;
for(i=1;i<=n;i++)
if(i%m==0)
cout<<i<<“,”;
getchO;
}
c) #include<iostream.h>
#include<conio.h> 
void main() 
{
clrscrO;
int i,n,m;
cout<<“Enter values for n and m”; 
cin>>n>>m; 
for(i=1;i<=n;i++)
 if(i%m==0)
{
cout<<i<<“\t”; 
if(i%2==0)
cout<<“even”<<endl; 
else
cout<<“odd”<<endl;
}
getch();
}
OR
#include<iostream.h>
#include<conio.h>
#include<string.h>//for strlen() 
main()
{
clrscr();
int n,i,j;
cout<<“enter a value for n:”; 
cin>>n; 
for(i=n;i>0;i--)
{
for(j=n;j>=i;j--) 
cout<<j*j<<“\t”; 
cout<<endl;
}
getch();
}

Question 10.
Write a C++ program to display the Fibonacci series. (Say – 2015)
Answer:

#include<iostream> 
using namespace std; 
int main()
{
int n,fib1=0,fib2=1,fib3; 
cout<<”Enter the limit";
cin>>n;
cout<<"The fibonacci series is ";
if(n==1)
cout<<fib1<<","; 
else if(n==2)
cout<<fib1 <<","<<fib2<<","; 
else if (n>2)
{
cout<<fib1 <<","<<fib2<<","; 
fib3=fib1+fib2; 
while(fib3<=n)
{
cout<<fib3<<","; 
fib1=fib2; fib2=fib3;
fib3=fib1+fib2;
}
}
else
cout<<"lnvalid";
}

Question 11.
Write a C++ program to accept an integer number and check whether it is an Armstrong number or not. (March – 2016)
(Hint: Sum of the cubes of the digits of an Armstrong number is equal to that number itself)
OR
Write a C++ program to accept an integer number and print its reverse
(Hint: If 234 is given, the output must be 432).
Answer:

a) #include<iostream> 
using namespace std; 
int main()
{
int n,m,rem,cube=0;
cout<<"Enter a number";
cin>>n;
m=n;
while(n)
{
rem=n%10;
cube=cube+rem*rem*rem; 
n=n/10;
}
if(cube==m)
cout<<"The number "<<m<<" is Armstrong"; 
else
cout<<"The number"<<m<<" is not Armstrong";
}
OR
(b) # include<iostream> 
void main ()
{
int n, rem, rev = 0; 
cout<<“Enter a number:’’; 
cin>>n; while (n)
{
rem = n%10; 
rev = rev*10+rem; 
n = n/10;
}
cout<< “The reverse is” << rev;
}

Question 12.
Write a program to check whether the given number is palindrome or not. (March – 2017)
OR
Write a program to print the leap years between 2000 and 3000.
(A century year is leap year only if it is divided by 400 and a noncentury year is leap year only if it is divided by 4).
Answer:

#include<iostream> 
using namespace std; 
int main()
{
int n,m,rem,rev=0;
cout<<“Enter a number”;
cin>>n;
m=n;
while(n)
{
rem=n%10;
rev=rev*10+rem;
n=m/10;
}
if(rev==m)
cout<<“The number “<<m<<“ is palindrome”; 
else
cout<<“The number “<<m<<“ is not palindrome”;
}
OR
#include<iostream> 
using namespace std; 
int main()
{
int year;
for(year=2000;year<=3000;year++)
{
if(year%100==0)
{
if(year%400==0)
cout<<year<<endl;
}
else
{
if(year%4==0)
cout<<year<<endl;
}
}
}

Plus One Computer Science Chapter Wise previous Questions

Leave a Comment