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

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