C - Counting with the for statement

Introduction

The following code shows counting variation.

Demo

#include <stdio.h> 

int main() // www .  j a va 2 s. c o  m
{ 
     int i; 

     for(i=2;i<=100;i=i+2) 
     { 
         printf("%d\t",i); 
     } 
     putchar('\n'); 
     return(0); 
}

Result

The program's output displays even values from 2 through 100.

The value 100 is displayed because the "while true" condition in the for statement uses <= (less than or equal to).

The variable i counts by two because of this expression:

i=i+2 

printf() function uses \t to display tabs. putchar() function kicks in a newline character.

Related Example