Example program of switch statement
#include <iostream.h>
int main ()
{
int num;
cout<<”\n Enter any number between 0-9:”;
cin>>num;
switch(num)
{
case 0: cout<<”\n You entered ZERO”; break;
case 1: cout<<”\n You entered ONE”; break;
case 2: cout<<”\n You entered TWO”; break;
case 3: cout<<”\n You entered THREE”; break;
case 4: cout<<”\n You entered FOUR”; break;
case 5: cout<<”\n You entered FIVE”; break;
case 6: cout<<”\n You entered SIX”; break;
case 7: cout<<”\n You entered SEVEN”; break;
case 8: cout<<”\n You entered EIGHT”; break;
case 9: cout<<”\n You entered NINE”; break;
default: cout<<”\n You entered WORNG NUMBER”;
}
return 0;
}
No comments:
Post a Comment