Videos Related with Control Structures in C

Note on Control Structures in C

  • Note
  • Things to remember
  • Videos
  • Exercise
  • Quiz

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

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

Very Short Questions

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)

0%
  • What is the meaning of %d in C Language?

    Floating point
    Integer
    Square root
    Surd
  • %f is used in C Language for __________.

    float
    surd
    integer
    square root
  • What is the meaning of %s in C Language?

    Square root
    Integer
    String
    Float
  • What is the meaning of != in C Language?

    Not equals to
    Equals to
    AND
    OR
  • What is the meaning of x++ in C Language?

    Decrement
    Increment
    Constant
    Variable
  • You scored /5


    Take test again

DISCUSSIONS ABOUT THIS NOTE

You must login to reply

Forum Time Replies Report
Rj


You must login to reply