#include <stdio.h>
#define TRANS 'a' - 'A';
int main(void)
{
char chWord;
while(chWord != -1)
{
chWord = getchar();
if(chWord > 64 && chWord < 91) // chWord가 대문자라면!
{
chWord = chWord + TRANS;
}
else if(chWord > 96 && chWord < 123) // chWord가 소문자라면!
{
chWord = chWord - TRANS;
}
printf("%c",chWord);
}
return 0;
}
입력하는 글자의 홀수번째 글자만 변환하도록 수정.
#include <stdio.h>
int main(void)
{
char szWord[100];
int nCount = 0;
int nTrans = 'a' - 'A';
gets(szWord);
while(szWord[nCount] != '\0') //문자 배열의 마지막은 널문자.
{
if((nCount % 2) == 0) //nCount가 홀수라면
{
if(szWord[nCount] >= 'A' && szWord[nCount] <= 'Z') // szWord가 대문자라면!
{
szWord[nCount] = szWord[nCount] + nTrans;
}
else if(szWord[nCount] >= 'a' && szWord[nCount] <= 'z') // szWord가 소문자라면!
{
szWord[nCount] = szWord[nCount] - nTrans;
}
}
nCount++;
}
printf("%s\n",szWord);
return 0;
}
댓글 없음:
댓글 쓰기