Advertisement

โค้ดโปรแกรมตัดเกรดภาษาซี โดยใช้ switch() ในตัวอย่างโค้ดด้านล่างนี้

Advertisement
/*
 * Code by DekDEV.com
 */
#include <stdio.h>

int main()
{
    int score;
    printf("Enter your score : ");
    scanf("%d", &score);

	switch(score/10){
		case 10: ;
		case 9: ;
		case 8:  printf("Score = %d , You Grade : A \n", score); break;
		case 7:  printf("Score = %d , You Grade : B \n", score); break; 
		case 6:  printf("Score = %d , You Grade : C \n", score); break;
		case 5:  printf("Score = %d , You Grade : D \n", score); break;
		default :  printf("Score = %d , You Grade : F \n", score); break;
	}

	return 0;
}

Advertisement