New student? Register here

# 12th Class Chapter 12 Computer science Short Questions

An important facility for 12th class students preparing for short questions computer science 12th class chapter 12 of BISE. Get hundreds of questions to prepare and get better marks in 12th computer science

### 0

Our database contains a total of 0 questions for computer science Short Questions. You’ll prepare using this huge databank.

##### Question: 1
Write the output of the following program fragments.
N= 0;
While (n<=4)
{
Printf ("%3d %3d \n", n,10=n);
N + +;
}

1-29
Output:
0, 10
1, 9
2, 8
3, 7
4, 6
##### Question: 2
Write any two uses of loop.
2-29
1. In any programming language , loops are used to execute a set of statements repeatedly until a particular condition is satisfied.
2. We don't want to write those multiple lines of code again and again, thus you put a loop.
##### Question: 3
What is the output of the following code?
{
Int n =1;
While (n< =5);
{
N= n+1;
}
Getch( );
}
3-29
Output:
##### Question: 4
Define While Loop.
4-29
The while loop keeps repeating associated statements until the specified condition becomes false. This is useful where the programmer does not know in advance how many times the loop will be traversed.The dyntax o the while statement is
While (condition)
}
statements(S);
}
The condition in the while loop controls iteration. The statements which are executed when the given condition is true,from the body of the loop. If the condition is true, the body of the loop is executed . As soon as it becomes false, the loop terminates immediately.
##### Question: 5
Predict the output of the following piece of code .
Int I =1;
While.(i< =5)
{
Printf ("Pakistan");
I ++;
}
5-29
Output:
Pakistan
Pakistan
Pakistan
Pakistan
Pakistan
Pakistan
##### Question: 6
Convert the following code into while loop.
For (int i =1;i< =10;i ++)
{
Printf("\nPakistan");
}
6-29
Conversion:
Void main ( )
{
Int i =1;
While(i< =10)
{
Printf("%\n",I);
I =i+1;
}}
##### Question: 7
Write the syntax of do -while loop, both for single statement and for multiple statement .
7-29
Syntax for Single Statement and Multiple Statement :
Do
{
Statement(s);
} while (condition);
##### Question: 8
Write syntax of while loop, both for single statement and for multiple statement.
8-29
Syntax for Single Statement and Multiple Statements:
While (condition)
{
statements(s);
}
##### Question: 9
Convert the following loop code into Do-while loop code.
Int n = 1;
While (n< =10)
{
Printf ("*\n");
N ++;
}
9-29
Conversion:
Void main ( )
{
Int n =1:
Do
{
Printf("%d\n" ,*);
N = n+1;
}while (n < =10);
}
##### Question: 10
Convert following loop code into while loop code.
For (I =10; >0; i --)
{
printf ("i = %d",i);
}
10-29
Conversion:
Void main( )
{
Int I = 10;
While (i>0)
{
Printf("i = %d",i);
i = I -1;
}
}
##### Question: 11
Write syntax of while loop, both for single statement and for multiple statement.
11-29
Syntax for Single Statement and Multiple Statements:
While (condition)
{
statements(s);
}
##### Question: 12
Trace the output .
Int a =1;
While (a < =6)
{
printf("\n a=%d",a)
a+ =1;
}
12-29
Output: 1
2
3
4
5
6

##### Question: 13
Find output of the following code.
#include <stdio.h>
Void main

{
Int i, p=1;
For (i = 1; I < 6; I +=1)
P* 2;
Printf ("p is = %d",p);
}
13-29
Output;
2
2
2
2
##### Question: 14
Rewrite the following code using do-while loop.
Int x= 10;
While (x> =1)
{ printf ("'%d", x%2);
x--;
}
14-29
Rewrite in do-while loop:
Void main ( )
{
Int x = 10;
Do
{
Printf("%d\n",x%2);
X=x-1;
}while (n>=1);
}
##### Question: 15
Convert while into do-while.

Int i =1;
While (I <=15)
{printf( "/n",1);
I = i+1;}
15-29
Conversion:
Void main ()
{
Int i =1;
Do
{
Printf("/n",1);
i =i+1;
} while ( i < =15);
}
##### Question: 16
Determine output of the following code segment.
Int n = 1;
Do
{
Printf("Pakistan\n");
N++;
} while (n<=4);
16-29
Output:
Pakistan
Pakistan
Pakistan
Pakistan
Write Output.
Int x= 5, y= 3;
Do
{
X= x *2;
Y = y+2;
}
While (y<7);
Printf("%d",x);
17-29
Output:
10
##### Question: 18
Convert the following loop in do-while loop.
For (i=3;i <39; i+=6)
{
Printf ("%d/n",i);
}
18-29
Conversion:
Void main( )
{
Int I =1;
Do
{
Fprintf("%d/n",i);
i+ =6;
}while (i<39);
}
##### Question: 19
Trace the output.
Int I, j =10;
For (I = 1; i< =5; i + +)
{
Printf("\nPakistan");
}

19-29
Output:
Pakistan
Pakistan
Pakistan
Pakistan
Pakistan
##### Question: 20
What is the following code in for loop.
Int n=1;
While (n< =10);
{
Printf("%d\n",n);
N++;
}
20-29
Conversion:
Void main ( )
{
Int n;
For (n=1; n< =10; n++)
Printf(("%d\n",n);)
}

##### Question: 21
Predict the output from the following code.
Int n;
Clrscr ();
For (n = 5; n > = 1; n --)
Printf ("%d\n',n);
getch();
21-29
Output:
5
4
3
2
1
##### Question: 22
Convert the following loop Code into for loop code.
i= 3;
Do
{
Printf ("%d/n",i);
I + =3;
}
While (i < =21);
22-29
Conversion
Void main
{
int i:
for (i =3; i<=21; i + =3)
printf ("%d\n",i);
}
##### Question: 23
Define for Loop.

23-29
For Loop: The for statement is another way of implementing loops in C. Because of its flexibility, most programmers prefer the for statement to implements loops.
Syntax: The syntax of the for loops is as follows:
For (initialization expression: test condition;
increment/decrement expression)
{
Statement(s);
}
##### Question: 24
Trace the erros of the following code.
Void main( )
{
Int x, y= 5;
For (x= 0; x < 3;x ++)
If (y > =5)
Print f ("%s\t",x);
}
24-29
Errors:
0 1 2
##### Question: 25
Define go to statement.
25-29
The go to statement performs an unconditional transfer of control to the name label.The label must be in the same function. A label is meaningful only to a goto statement: in any other context, the labeled statements is
Executed without regard to the label .
General Form: The general form of the goto statement is as follows:
Goto label:
.................,
Label: statement
##### Question: 26
Show output.
Int m;
For (m =0; m> = 0; + +)
Printf("%d\t",m);
26-29
Output:
0,1,2,3,45,6,78,9,..........................
##### Question: 27
Convert the following do-while loop in for loop.

Int c=2;
Do
Printf ("C".c);
While (c + +< =5);

27-29
Conversion:
Void main ( )
{
Int c;
For (c=2; c < =5; c+ +)
{
Printf (" %C",c);
}
}
##### Question: 28
Define nested loop.

28-29
Nested Loop: Nested loop mean a loop inside the body of another loop.Nesting can be done up to any level. But as the level of nesting increase, the complexity of the nested loop also increase . There is no instruction on the type of loops (while , do-while , or for ) that may be placed in the body of other loops.
Example: we can place one or more while or so-while loops in the body for the loop. Similarly, one or more for loops can be placed in the body of while or do -while loop.

##### Question: 29
What is sentinel controlled loop?