Subject: Computer Science
syntax:
if (condition)
{
statement;
}
else if (condition)
{
statements;
}
..............
else
{
statements
}
/*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");
syntax:
for(initialize, condition, increment)
{
statement block
}
Example
#include
main()
{
int x;
for(x=1;x<=10;x++)
{
printf("%d\n",x);
}
syntax
while(condition)
{
statement block
}
#include
main()
{
int x;
x=1;
while(x<=10)
{
printf("%d\n",x);
x++;
}
syntax
do
{
statement block;
}while(condition)
#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);
}
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)
© 2019-20 Kullabs. All Rights Reserved.