728x90
반응형

문제 : https://codeup.kr/problem.php?id=1204

 

영어 서수로 표현하기

영어로 서수를 표현할 때 다음과 같이 나타낸다. 1st  2nd  3rd  4th  5th  6th  ... 10th 11th 12th 13th 14th 15th  ...  20th 21st 22nd 23rd 24th 25th  ...  30th 31st 32nd 33rd 34th 35th  ...  40th 41st 42nd 43rd 44th 45th  ...

codeup.kr

 

문제 설명

영어로 서수를 표현할 때 다음과 같이 나타낸다.

1st  2nd  3rd  4th  5th  6th  ... 10th

11th 12th 13th 14th 15th  ...  20th

21st 22nd 23rd 24th 25th  ...  30th

31st 32nd 33rd 34th 35th  ...  40th

41st 42nd 43rd 44th 45th  ...  50th

...

91st 92nd 93rd 94th 95th  ...  99th

 

1~99 중 하나가 숫자가 입력되면 영어 서수 표현을 출력하시오.

 

 

[그림1] 입 출력 형식 및 예제

 

 

#include <stdio.h>

int main(){
    int num,i=0;
    scanf("%d",&num);
    i=num%10;
    if(num==11||num==12 || num==13){
        printf("%dth",num);
    }
    else if(i>=4){
        printf("%dth",num);
    }
    else if(num%10==1){
        printf("%dst",num);
    }
    else if(num%10==2){
        printf("%dnd",num);
    }
    else if(num%10==3){
        printf("%drd",num);
    }
    else if(num%10==0){
        printf("%dth",num);
    }
    
    return 0;
}
728x90
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기