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

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