You must sign in Login/Signup

New student? Register here

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
Generic placeholder image

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 + +;
}

Answer: 1
1-29
Output:
0, 10
1, 9
2, 8
3, 7
4, 6
Question: 2
Write any two uses of loop.
Answer: 2
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);
{
Printf ("Islam Zindabad");
N= n+1;
}
Getch( );
}
Answer: 3
3-29
Output:
Islam Zindabad
Islam Zindabad
Islam Zindabad
Islam Zindabad
Islam Zindabad
Question: 4
Define While Loop.
Answer: 4
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 ++;
}
Answer: 5
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");
}
Answer: 6
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 .
Answer: 7
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.
Answer: 8
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 ++;
}
Answer: 9
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);
}
Answer: 10
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.
Answer: 11
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;
}
Answer: 12
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);
}
Answer: 13
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--;
}
Answer: 14
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;}
Answer: 15
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);
Answer: 16
16-29
Output:
Pakistan
Pakistan
Pakistan
Pakistan
Question: 17
Write Output.
Int x= 5, y= 3;
Do
{
X= x *2;
Y = y+2;
}
While (y<7);
Printf("%d",x);
Answer: 17
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);
}
Answer: 18
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");
}

Answer: 19
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++;
}
Answer: 20
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();
Answer: 21
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);
Answer: 22
22-29
Conversion
Void main
{
int i:
for (i =3; i<=21; i + =3)
printf ("%d\n",i);
}
Question: 23
Define for Loop.

Answer: 23
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);
}
Answer: 24
24-29
Errors:
0 1 2
Question: 25
Define go to statement.
Answer: 25
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);
Answer: 26
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);

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

Answer: 28
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?
Answer: 29
29-29
One way to do this is to instruct the user to enter a unique data value, called a sentinel value, after the last data item . The loop condition test s each data item and causes loop exit when the sentinel value is read. Choose the sentinel value is read.Choose the sentinel value carefully;
It must be a value that could not normally occur as data. The general form of a sentinel-controlled loop is;
  1. Get the first line of data
  2. While the sentinel value has not been encountered
  3. Process the data line.
  4. Get another line of data