3_third Chapter r Looping Statemnt
3_third Chapter r Looping Statemnt
Control statement are use if we want to perform the some task repetitively again and again.
Entry control loop means if condition satisfy or true first time then loop will be execute
otherwise not
Ii]while loop
May be condition false first time loop will execute minimum single time is called
As.exit control loop .if condition is true then loop will execute same as entry control loop.
If we want to use the any type of loop we need three important steps.
Ii]condition:-how many time will be repeat or how may be repetation you want
To perform.
{
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
Output:-
Good morning
Good morning
Good morning
Good morning
Good morning
First time i=1 is less than 5 then condition is true and loop will be execute
And print the good morning message then I will increment by 1 then next
Time i=2 this is also true so loop will be execute and print the good morning
//Following programme demonstrate the use of for loop for print the table
#include<stdio.h>
#include<conio.h>
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
void main(){
int no,table,I;
clrscr();
scanf(“%d”,&no);
for(i=1;i<=100;i++)
table=no*I;
printf(“%d\n”,table);
getch();
Output:-
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
Syntax:- Intilization ;
While(condition)
while(i<=5)
Printf(“good morning”);
I++;
Syntax :-Intalization;
Do
Statement block
Increment or decrement
While(condition);
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
//Following programme demonstrate the use of do while loop for display the
table
#include<stdio.h>
#include<conio.h>
void main(){
int no,table.i;
clrscr();
scanf(“%d”,&no);
i=1;
while(i<=no)
{
table =i*no;
printf(“%d\n”,table);
i++;
getch();
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
Break:-this keyword is used to stop the execution of loop in middle if programmer want.
Continue:- This keyword is used to skip some the execution step of loop if programme want.
#include<conio.h>
void main(){
int i;
clrscr();
for(i=1;i<=5;i++)
if(i==3)
break;
else
printf(“good morning”);
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
getch();
This programme geneate the output good morning two times because condition satisfy
#include<conio.h>
void main(){
int I,j,table;
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
clrscr();
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
tacle=i*j;
printf(“%d”,table);
printf(“\n”);
getch();
Output:-
#include<conio.h>
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
void main(){
int marks1,marks2,marks3,sum;
char choice;
clrscr();
do{
scanf(“%d%d%d”,&marks1,&marks2,&marks3);
sum=marks1+marks2+marks3;
printf(\n cont……………(Y/N):”);
fflush(stdin);
choice=getche();
while(choice!=’n’&&choice!=’N’)
getche();
Output:
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
#include<conio.h>
void main(){
long first=0,second=1,third;
int i,num;
clrscr();
scanf(“%d”,&num);
printf(“\n %ld\t%ld”,first,second);
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
for(i=2;i<num;i++)
third=first+second;
printf(“\t %ld”,third);
first=second;
second=third;
getche();
Output:-
#include<conio.h>
void main(){
int num,i,rem;
clrscr();
scanf(“%d”,&num);
for(i=2;i<num/2;i++)
rem=num%i;
if(rem==0)
break;
if(i==(num/2))
getch();
Output:-
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
#include<conio.h>
void main(){
int i,j,k;
clrscr();
printf(“\n first\n”);
for(i=1;i<=5;i++)
for(j=1;j<=i;j++)
printf(“*\t”);
printf(“\n”);
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
printf(“*\t”);
printf(“\n”);
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
for(i=1;i<=5;i++)
for(k=4;k>=i;k--)
printf(“\t “);
for(j=1;j<=i;j++)
printf(“*\t”);
printf(“\n”);
getch();
Output:-
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
#include<conio.h>
void main(){
long num,rev=0,temp;
int rem,count=0,sum=0;
clrscr();
scanf(“%ld”,&num);
temp=num;
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
while(num>0)
rem=num%10;
num=num/10;
count++;
sum+=rem;
rev=rev*10+rem;
getch();
Output:
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
#include<conio.h>
void main(){
int i;
clrscr();
for(i=1;i<=5;i++)
if(i==3)
continue;
else
printf(“good morning”);
getch();
Output:-
This program four time good morning message.if condition satisfy in loop then if will skip
one
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
#include<conio.h>
void main(){
int num,sum,temp,rem,limit;
clrscr();
scanf(“%d”,&limit);
for(num=1;num<=limit;num++)
sum=0;
temp=num;
while(temp>0)
rem=temp%10;
sum=sum+rem*rem*rem;
temp/10;
if(sum==num)pPrintf(“\t %d”,sum);
getch();
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
Output:-
#include<conio.h>
void main(){
int num,sum=0,temp,rem;
clrscr();
scanf(“%d”,&num);
temp=num;
while(num>0)
rem=num%10;
sum=sum+rem*rem*rem;
num/=10;
}
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)
if(sum==temp)
else
getch();
Output:-
GIRI’S TECH HUB,Pune(IT Training Institute with 100% Guaranteed Placement Support Mob:9175444433)