본문 바로가기
C and C++/C and C++ Examples

[C Examples] 7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d

by Henry Cho 2023. 2. 15.
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

댓글