In this program, the task is to take input of a series of n elements and print them on the output screen using do-while loop . The program consist of an array a[10], in which elements will be stored. Now,the condition of do-while loop is checked at last (dats why it is called as exit controlled loop).loop will start executing.
Syntax : -
initialization;
do
{ content;
updation
}while(condition check);
Execution of for loop : -
1.initialization
2.condition check
3.content executes
4.updation & go to tep 2;
Syntax : -
initialization;
do
{ content;
updation
}while(condition check);
Execution of for loop : -
1.initialization
2.condition check
3.content executes
4.updation & go to tep 2;
Program using Do While.
#include<stdio.h>#include<conio.h>
void main()
{ int i=0,a[10],n;
clrscr();
printf("\nto execute do-while loop :");
printf("\n\n enter the no. of no.s :");
scanf("%d",&n);
printf("\nenter them : \n");
do
{ printf("enter a[%d] : ",i);
scanf("%d",&a[i]);
i++;
}while(i<n);
printf("\n\n values entered in array are : \n");
i=0;
do
{ printf("\n a%d = %d",i,a[i]);
i++;
}while(i<n);
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.