Switch inside for loop : Switch « Language Basics « C / ANSI-C






Switch inside for loop

  
#include <stdio.h>

main() {
    int i,n;
    
    scanf("%d",&n); 
    
    for(i = 1; i<n; i= i+1) {
       switch(i%2) {
           case 0 : printf("the number %d is even \n",i);
              break;   
           case 1 : printf("the number %d is odd \n",i);
              break;
       }

    }

}

           
       








Related examples in the same category

1.a simple 4 function calculator
2.Switch demo
3.How to use switch: number
4.How to use switch: char
5.Switch: char and nested if
6.Switch with int case
7.Switch with char case
8.Get three input at the same time: scanf
9.Console menu: switch with char case
10.Switch with default