TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Saturday, 9 May 2020

Loop statement In C Language | Loop statement In C Language In Hindi


Loop statement In C Language



Loop are used to repeat a block of statement for a certain time.

There are three type of loop they are:

1.while loop
2.do-while loop
3.for loop


1.while loop

This loop execute a statement or a block of statement until the specified Boolean expression evaluates to false.

Syntax:

While(expression)
{
//statement
}

download flowchart image of while loop

Fig: While loop 

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int   i=1;
while(i<=5)
{
printf(“%d\n”,i);
i++;
}
getch();
}


Output:

1
2
3
4
5


2.do-while loop

This loop execute a statement or a block of statement until the specified Boolean expression evaluates to false.


Syntax:

do
{
//statement
}
while(expression);

download flowchart image of do-while loop

Fig: do-while loop 


Program

#include<stdio.h>
#include<conio.h>
void main()
{
char choice=’Y’;
do
{
int    number=5;
printf(“\n print number :%d”,number);
printf(“\n Do you want to Continue (y/n)   :”);
scanf(“%c”, &choice);
}
while(choice==’y’);
getch();
}


Output:

Print number :5
Do you want to continue (y/n) : y


3. for loop

This loop has three sections-index declaration, condition(Boolean expression) and updating section, in each for loop iteration the index is update(incremented/decremented)  by updating section and checked with condition. 

If the condition is matched, it continue execution until the specified Boolean expression evaluates to false.


Syntax:

for(initialization statement, condition, increment/decrement)
{
//statement;
}

download flowchart image of while loop

Fig: for loop 


Program

#include<stdio.h>
#include<conio.h>
void main()
{
int   a,f,i;
printf(“Enter a number :  “);
scanf(“%d”,&a);
f=1;
for(i=1;i<=a;i++)
f=f*i;
printf(“factorial  : %d”, f);
getch();
}


Output:

Enter a number :5
Factorial: 120



No comments:

Post a Comment