Google

Friday, January 15, 2010

CSC202 & ENG4033M : Switch

/*Switch */
#include "stdio.h"
int main()
{
int i;

printf("enter a integer: ");
scanf("%d",&i);

switch(i){
case 0:
printf("zero\n");
break;
case 1:
printf("one\n");
break;
case 2:
printf("two\n");
break;
case 3:
printf("three\n");
break;
default:
printf("other number\n");
break;
}

return 0;
}



/*else if */
#include "stdio.h"
int main()
{
int i;

printf("enter a integer: ");
scanf("%d",&i);

if(i==0) printf("zero\n");
else if(i==1) printf("one\n");
else if(i==2) printf("two\n");
else if(i==3) printf("three\n");
else printf("other number\n");


return 0;
}