Control Structures in C

Subject: Computer Science

Find Your Query

Overview

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

Scholarships after +2 Abroad Studies Opportunities

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

Things to remember
  • Different types of Control structures are: For control, While control and Do control.
  • It includes every relationship which established among the people.
  • There can be more than one community in a society. Community smaller than society.
  • It is a network of social relationships which cannot see or touched.
  • common interests and common objectives are not necessary for society.
Videos for Control Structures in C
C Programming Making Statements IF, For, Do while, Goto
C Programming Do while Loops
C Programming While loop, Continue, Break
Questions and Answers
C language is popular than QBASIC because of following reasons:

  • C language is simple, reliable and easy to use.
  • C language can be used for developing application programs and system programs whereas QBASIC is used for developing application program only.
  • C language has enough number of built in functions and operators whereas QBASIC has limited data type.

The syntax for if else is:
if (condition)
{
statement;
}
else if (condition)
{
statements;
}
..............
else
{
statements
}

The syntax for While control is:
while(condition)
{
statement block
}

The syntax for Do control is:
do
{
statement block;
}while(condition)

Quiz

© 2019-20 Kullabs. All Rights Reserved.