jiwonn7098   7달 전

[ 첫번째 소스코드 ]

#include <stdio.h>
#include <string.h>

int main(void)
{
int N;
float grade, gresult = 0, sresult = 0;
float result;
char subject[200] = { 0, }, score[3] = { 0, };
scanf("%d", &N);

for (int i = 0; i < N; i++)
{
scanf("%s %f %s", subject, &grade, score);

if (strcmp(score, "A+") == 0)
sresult += (4.3 * grade);
else if (strcmp(score, "A0") == 0)
sresult += (4.0 * grade);
else if (strcmp(score, "A-") == 0)
sresult += (3.7 * grade);
else if (strcmp(score, "B+") == 0)
sresult += (3.3 * grade);
else if (strcmp(score, "B0") == 0)
sresult += (3.0 * grade);
else if (strcmp(score, "B-") == 0)
sresult += (2.7 * grade);
else if (strcmp(score, "C+") == 0)
sresult += (2.3 * grade);
else if (strcmp(score, "C0") == 0)
sresult += (2.0 * grade);
else if (strcmp(score, "C-") == 0)
sresult += (1.7 * grade);
else if (strcmp(score, "D+") == 0)
sresult += (1.3 * grade);
else if (strcmp(score, "D0") == 0)
sresult += (1.0 * grade);
else if (strcmp(score, "D-") == 0)
sresult += (0.7 * grade);
else if (strcmp(score, "F") == 0)
sresult += (0 * grade);

gresult += grade;
}

result = sresult / gresult;

printf("%.2f\n", result);
return 0;
}



[ 두번째 소스코드 ]


#include <stdio.h>
#include <string.h>

int main(void)
{
int N;
float grade, gresult = 0, sresult = 0;
float result;
char subject[200] = { 0, }, score[3] = { 0, };
scanf("%d", &N);

for (int i = 0; i < N; i++)
{
scanf("%s %f %s", subject, &grade, score);

if (strcmp(score, "A+") == 0)
sresult += (4.3 * grade);
else if (strcmp(score, "A0") == 0)
sresult += (4.0 * grade);
else if (strcmp(score, "A-") == 0)
sresult += (3.7 * grade);
else if (strcmp(score, "B+") == 0)
sresult += (3.3 * grade);
else if (strcmp(score, "B0") == 0)
sresult += (3.0 * grade);
else if (strcmp(score, "B-") == 0)
sresult += (2.7 * grade);
else if (strcmp(score, "C+") == 0)
sresult += (2.3 * grade);
else if (strcmp(score, "C0") == 0)
sresult += (2.0 * grade);
else if (strcmp(score, "C-") == 0)
sresult += (1.7 * grade);
else if (strcmp(score, "D+") == 0)
sresult += (1.3 * grade);
else if (strcmp(score, "D0") == 0)
sresult += (1.0 * grade);
else if (strcmp(score, "D-") == 0)
sresult += (0.7 * grade);
else if (strcmp(score, "F") == 0)
sresult += (0 * grade);

gresult += grade;
}

printf("%.2f\n", sresult / gresult);
return 0;
}





****

두 소스코드는 마지막 줄만 다른데 왜 첫번째 소스코드는 맞는 코드고

두번째 소스코드는 틀린 코드인가요?



댓글을 작성하려면 로그인해야 합니다.