제어문으로 성적산출

if문

#include <stdio.h>
int main() {
int score;

printf("점수 : ");
scanf("%d", &score);

if (score >= 90) {
printf("A");
}
if(90 > score && score >= 80) {
printf("B");
}
if (80 > score && score >= 70) {
printf("C");
}
if (70 > score && score >= 60) {
printf("D");
}
if (60 > score) {
printf("E");
}

return 0;
}

if, else if, else 문

#include <stdio.h>
int main() {
int score;

printf("점수 : ");
scanf("%d", &score);

if (score >= 90) {
printf("A");
}
else if (score >= 80) {
printf("B");
}
else if (score >= 70) {
printf("C");
}
else if (score >= 60) {
printf("D");
}
else {
printf("E");
}

return 0;
}

switch-case 문

#include <stdio.h>
int main() {
int score;

printf("점수 : ");
scanf("%d", &score);

switch (score / 10) {
case 10:
case 9:
printf("A");
break;
case 8:
printf("B");
break;
case 7:
printf("C");
break;
case 6:
printf("D");
break;
default:
printf("E");
break;
}

return 0;
}
Total views

댓글

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×