Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

for loop-:


for loop is a counter controlled loop,perhaps the most commonly used looping statement in C programming. It is used to repeatedly execute either a single or a group of statement for a finite number of times.
Syntax-:
for(Initialization;Testing;Increment/Decrement)                                                                      
ads

  • Initialization-: This expression is used to initialize same parameter [called an index],that control the looping action.
  • Testing Expression-: It represent a condition that must be TRUE for the loop to continue its execution.
  • Increment/Decrement Expression-: It is a unary expression or an assignment expression.It increment or decrement the index so that the loop continue.
Example-:
#include<stdio.h>
#include<conio.h>
main()
{ int i=0;
   for(i=1;i<=5;i++)
   printf("\n %d",i);
   getch();
}
Output-: 1
                2
                3
                4
                5
Example-:write a program to find sum of series 1+2+3+----
#include<stdio.h>
#include<conio.h>
main()
{int i=0,term=0,s=0;
  printf("Enter the term");
  scanf("%d",&term);
  for(i=1;i<=term;i++)
  s=s+i;
  printf("\n sum=%d",s);
  getch();
}
Output-: Enter the term 3
               sum=7
Watch The Video Below


ads

Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey