728x90
7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d
포스트 난이도: HOO_Junior
# Example Codes
#include <stdio.h>
int main()
{
int frontISSN, frontISSNOne, frontISSNTwo, frontISSNThree, frontISSNFour,
backISSN, backISSNOne, backISSNTwo, backISSNThree, backISSNPer, modNum,
unknownNum;
printf("Enter the 7 digit ISSN in form of XXXX-XXX:");
scanf("%d - %d", &frontISSN, &backISSN);
frontISSNOne = frontISSN/1000;
frontISSNTwo = (frontISSN - (frontISSNOne*1000)) /100;
frontISSNThree = (frontISSN-(frontISSNOne*1000)-(frontISSNTwo*100))/10;
frontISSNFour = (frontISSN-(frontISSNOne*1000)-(frontISSNTwo*100)-
(frontISSNThree*10));
backISSNOne= backISSN/100;
backISSNTwo = (backISSN - (backISSNOne*100))/10;
backISSNThree = (backISSN - (backISSNOne*100)-(backISSNTwo*10));
backISSNPer=((frontISSNOne)*8 + (frontISSNTwo)*7 + (frontISSNThree)*6 +
(frontISSNFour)*5 + (backISSNOne)*4 + (backISSNTwo)*3 + (backISSNThree)*2);
modNum = backISSNPer % 11;
unknownNum = 11 - modNum;
if (unknownNum == 10){
if(frontISSNOne==0){
printf("The complet 8 digit ISSN including check digit is [ 0%d-%dX ]\n",
frontISSN, backISSN);
}
else{
printf("The complet 8 digit ISSN including check digit is [ %d-%dX ]\n",
frontISSN, backISSN);
}
}
else{
if(frontISSNOne==0){
printf("The complet 8 digit ISSN including check digit is [ 0%d-%d%d ]\n",
frontISSN, backISSN, unknownNum);
}
else{
printf("The complet 8 digit ISSN including check digit is [ %d-%d%d ]\n",
frontISSN, backISSN, unknownNum);
}
}
printf("Coded by HOO.");
return 0;
}
Enter the 7 digit ISSN in form of XXXX-XXX:2387-997
The complet 8 digit ISSN including check digit is [ 2387-9971 ]
Coded by HOO.
Enter the 7 digit ISSN in form of XXXX-XXX:2378-881
The complet 8 digit ISSN including check digit is [ 2378-881X ]
Coded by HOO.
728x90
'C and C++ > C and C++ Examples' 카테고리의 다른 글
[C Examples] 24시간을 12시간 표기로 바꾸기 예제코드: if(), else (0) | 2023.02.18 |
---|---|
[C Examples] GPA 계산기 예제코드: if(), else if() (0) | 2023.02.17 |
[C Examples] 달러를 동전으로 바꾸는 예제코드 (0) | 2023.02.08 |
[C Examples/Q&A] 체질량 지수(BMI) 계산하는 예제코드: if, else if, && (0) | 2023.02.07 |
[C Examples] Circle area, circumference of circle 계산기 (0) | 2023.01.31 |
댓글