while
statement: While statement is used for repetitive
execution of statements more than once.
Syntax: while(condition)
{
-
- -
-
- - code block
(Statements)
}
Here,
Ø First the condition is
evaluated. It produces either TRUE or
FALSE.
Ø If the condition is TRUE,
then Code Block (Statements) will be executed, again control reaches to
condition section and is evaluated.
Ø The process is repeated until
the condition becomes FALSE.
Ø When the condition reaches to
FALSE, then the control is transferred out of the loop.
Flowchart:
/* PROGRAM TO PRINT FIRST N
NATURAL NUMBERS */
#include<stdio.h>
#include<conio.h>
main()
{
int i=1,n;
clrscr();
printf("\n Enter how many numbers:");
scanf("%d",&n);
printf("\n Natural Numbers Are:");
while(i<=n)
{
printf(" %3d",i);
i++;
}
}
No comments:
Post a Comment