/* The traffic light program (switch) */ #include <stdio.h> int main (void) { char colour; /* ask user for colour */ printf ("Enter the colour of the light (R,G,Y,A): "); scanf ("%c", &colour); /* test the alternatives */ switch (colour) { /* red light */ case 'R': case 'r': printf ("STOP! \n"); break; /* yellow or amber light */ case 'Y': case 'y': case 'A': case 'a': printf ("CAUTION! \n"); break; /* green light */ case 'G': case 'g': printf ("GO! \n"); break; /* other colour */ default: printf ("The colour is not valid.\n"); }
- Introduction
- Computer Language
- Programming Language
- Low and High Level Language
- Language Translators
- C Language
- Structure of C Language
- Variables and Constants
- Data Type , Constant Macro and Identifiers
- Keywords, Comments and Type Casting
- Operators with its Precedence and Associativity
- Input and Output functions
- Scanf
- getch(),getche(),gets function
- printf and puts function
- Escape sequence
- Format Specifeir and Feild Width Specifeir
- Character Array,clear screen and size of operator
- Character Input
- Control Structure
- Selection Structure,if statement and limitation of if statement
- if-else and if-else if statement
- Nested if
- Switch Statement
- Conditional Operator
- Loops
- while,do and for loop
- Nested loop
- Continue,goto and break statement
- Functions
- Variables,scope and lifetime of a variable
- Examples