티스토리 뷰
1. 내가 한 것 : strcmp() 이용
#include <stdio.h>
int main(void)
{
char word1[1000]={0}, word2[1000]={0}, word3[1000]={0};
char input[1000];
printf("세 단어 입력 : ");
scanf("%s%s%s",word1, word2, word3);
if(strcmp(word1,word2)<=0)
{
if(strcmp(word1,word3)<=0)
{
if(strcmp(word2,word3)<=0)
{
printf("%s %s %s",word1,word2,word3);
}
else printf("%s %s %s",word1,word3,word2);
}
else printf("%s %s %s",word3,word1,word2);
}
else printf("%s %s %s",word3,word2,word1);
return 0;
}
-------------------------------------------------------
세 단어 입력 : student mother father
father mother student
2. 다른 방법 : strcpy() 및 임시변수 이용
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[20], str2[20], str3[30];
char temp[20];
printf("세 개의 단어 입력 : ");
scanf("%s%s%s", str1, str2, str3);
// st1이 str2보다 사전의 뒤에 나오면 두 문자열을 바꾼다
if(strcmp(str1, str2) > 0)
{
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
}
// st1이 str3보다 사전의 뒤에 나오면 두 문자열을 바꾼다
if(strcmp(str1, str3) > 0)
{
strcpy(temp, str1);
strcpy(str1, str3);
strcpy(str3, temp);
}
// st2이 str3보다 사전의 뒤에 나오면 두 문자열을 바꾼다
if(strcmp(str2, str3) > 0)
{
strcpy(temp, str2);
strcpy(str2, str3);
strcpy(str3, temp);
}
printf("%s, %s, %s\n", str1, str2, str3);
return 0;
}
-----------------------------------------------
세 개의 단어 입력 : student mother father
father, mother, student
'Test > C' 카테고리의 다른 글
get_next 함수를 직접 작성하여 주어진 배열값의 합을 구하는 프로그램 (0) | 2017.08.09 |
---|---|
실수 a,b값을 swap 함수를 만들어 교체 (0) | 2017.08.09 |
입력한 단어중 가장 긴단어의 길이를 알랴줌 (0) | 2017.08.09 |
배열쓰지 않고 입력하는 알파벳열의 대소문자 바꾸기 (0) | 2017.08.09 |
로또 번호 6개를 선택하고 랜덤 생성한 6개의 당첨번호와 비교 (0) | 2017.08.08 |
- Total
- Today
- Yesterday
- insert
- sysprep
- dp-2
- vmware
- dp-1
- 차집합
- cloud-init
- powercli
- 대소문자
- 배열
- set()
- artandculture
- storage
- 읽어오기
- Join
- vmware.powercli
- 변수화
- fromkeys
- 중복제거
- LIST
- virt-sysprep
- EXA
- 부동없이
- dezoomify
- exadata
- 3par
- powershell
- 정렬
- 스토리지
- oracle
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |