Control Structures in C

Different types of Control Structures in C are: For control, While control and Do control.This note provides an information about control structures in C.

Summary

Different types of Control Structures in C are: For control, While control and Do control.This note provides an information about control structures in C.

Things to Remember

  • Different types of Control structures are: For control, While control and Do control.

MCQs

No MCQs found.

Subjective Questions

Q1:

Following table displays the marks obtained by three students Grade IX in three subjects, Full marks of any subject English,Mathematics and Nepali are 100.

(a) Express the information in matrix form.

(b) How many elements are there in the matrix? What is the order of the matrix?

(c) If the matrix is denoted by M, how is it written stating its order.

  A B C
English 60 70 68
Mathematics 80 92 71
Nepali 65 62 55

Type: Long Difficulty: Easy

Show/Hide Answer
Answer: <p>soln:</p>
<p>(a) Writing the given information in the form of matrix,we get,</p>
<p>First Second Third</p>
<p>Column Column Column</p>
<p>\(\begin{bmatrix} 60 &amp; 70 &amp; 68 \\ 80 &amp; 92 &amp; 71 \\ 65 &amp; 62 &amp; 55 \\ \end{bmatrix}\)</p>
<p>here row gives the different students and column gives the marks obtained in each subject.</p>
<p>(b) There are 3 rows and 3 columns in the above matrix. So its order is 3&times;3.</p>
<p>(c) If the above matrix is represented by M, the,</p>
<p>M=\(\begin{bmatrix} 60 &amp; 70 &amp; 68 \\ 80 &amp; 92 &amp; 71 \\ 65 &amp; 62 &amp; 55 \\ \end{bmatrix}\)</p>
<p>Here order of M is 3&times;3. This can be written in the matrix notation as</p>
<p>M<sub>3&times;3</sub> or,\(\begin{bmatrix} 60 &amp; 70 &amp; 68 \\ 80 &amp; 92 &amp; 71 \\ 65 &amp; 62 &amp; 55 \\ \end{bmatrix}\)<sub>3&times;3</sub></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

Q2:

If B=\(\begin{bmatrix} 20  & 35 & 55 & 70 \\ 25 & 45 & 60 & 75 \\ 30 & 50 & 65 & 80 \\ \end{bmatrix}\)

(a) How many elements are there in B?

(b) What is the order of B? Write down the matrix B in order notation.

 


Type: Short Difficulty: Easy

Show/Hide Answer
Answer: <p>Soln:</p> <p>here given matrix,</p> <p>B=\(\begin{bmatrix} 20 &amp; 35 &amp; 55 &amp; 70 \\ 25 &amp; 45 &amp; 60 &amp; 75 \\ 30 &amp; 50 &amp; 65 &amp; 80 \\ \end{bmatrix}\)</p> <p>(a) In matrix B, there are 12 elements in 3 rows and 4 columns.</p> <p>(b) There are 3 rows and 4 columns. So, its size is 3&times;4.</p> <p>It is written in the order nation as B<sub>3&times;4</sub> or, \(\begin{bmatrix} 20 &amp; 35 &amp; 55 &amp; 70 \\ 25 &amp; 45 &amp; 60 &amp; 75 \\ 30 &amp; 50 &amp; 65 &amp; 80 \\ \end{bmatrix}\)3&times;4</p> <p></p> <p></p>

Q3:

Is\(\begin{pmatrix} 0 & 0 \\ 0 & 0 \\ 0 & 0 \\ \end{pmatrix}\) equal to \(\begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0\\ 0 & 0 & 0 \\ \end{pmatrix}\)? state reason.


Type: Short Difficulty: Easy

Show/Hide Answer
Answer: <p>soln:</p> <p>Here given matrices,</p> <p>\(\begin{pmatrix} 0 &amp; 0 \\ 0 &amp; 0 \\ 0 &amp; 0 \\ \end{pmatrix}\) and \(\begin{pmatrix} 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0\\ 0 &amp; 0 &amp; 0 \\ \end{pmatrix}\). Both of these two matrices are null matrix but they are not equal size.</p>

Q4:

State that the given matrix is a square or a rectangular matrix.

\(\begin{bmatrix} 1 & 3 \\ 2 & 4 \\ \end{bmatrix}\)

 


Type: Very_short Difficulty: Easy

Show/Hide Answer
Answer: <p>&nbsp;</p>
<p>\(\begin{bmatrix} 1 &amp; 3 \\ 2 &amp; 4 \\ \end{bmatrix}\). here are two rows and two columns. So, it is a square matrix of order 2.</p>

Q5:

State that the given matrix is a square or a rectangular matrix. [1 2 3 ]


Type: Very_short Difficulty: Easy

Show/Hide Answer
Answer: <p>[1 2 3]. There are 1 row and 3 columns. So it is a row matrix of order 1&times;3.</p>

Q6:

State that the given matrix is a square or a rectangular matrix.

\(\begin{bmatrix} a & b & c \\ e & f & g \\ \end{bmatrix}\)


Type: Very_short Difficulty: Easy

Show/Hide Answer
Answer: <p>\(\begin{bmatrix} a &amp; b &amp; c \\ e &amp; f &amp; g \\ \end{bmatrix}\). Here are 2 rows and 3 columns. So, it is a rectangular matrix of order 2&times;3</p>

Q7:

State that the given matrix is a square or a rectangular matrix. 

\(\begin{bmatrix} 1 & 3 & 4 \\ 2 & 5 & 6 \\ \end{bmatrix}\)


Type: Very_short Difficulty: Easy

Show/Hide Answer
Answer: <p>\(\begin{bmatrix} 1 &amp; 3 &amp; 4 \\ 2 &amp; 5 &amp; 6 \\ \end{bmatrix}\). There are 2 rows and 3 columns. So, it is a rectangular matrix of order 2&times;3.</p>

Videos

Introduction to matrices
Modern Maths - Matrices
How to Use Matrices to Solve Linear Equations : Math Fundamentals
Control Structures in C

Control Structures in C

Branching with if

syntax:

if (condition)
{
statement;
}
else if (condition)
{
statements;
}
..............
else
{
statements
}

Example

/*check if the given number is positive, negative or zero*/

#include
main()
{
int h;
system("cls");
printf("Enter an integer;");
scanf("%d", &h);
if(h>0)
Printf("The number is positive");
else if(h=0)
printf("The number is zero");
else
printf("The number is negative");

For control

syntax:

for(initialize, condition, increment)
{
statement block
}

Example

#include
main()
{
int x;
for(x=1;x<=10;x++)
{
printf("%d\n",x);
}

While control

syntax

while(condition)
{
statement block
}

Example:

#include
main()
{
int x;
x=1;
while(x<=10)
{
printf("%d\n",x);
x++;
}

Do control

syntax

do
{
statement block;
}while(condition)

Example:

#include
main()
{
int x; sum=0;
do
{
printf("enter number");
scanf("%d",&x);
sum=sum+x;
}
while(x!=0);
{
printf("The sum of entered numbers:%d",sum);
}

Lesson

Structured Programming - C Language

Subject

Computer Science

Grade

Grade 10

Recent Notes

No recent notes.

Related Notes

No related notes.