개요
입력받은 단어를 알파벳을 a=1,b=2,...,z=26 숫자로 변환하고 합계를 구하라. |
Code
#include<stdio.h>
#include<string.h>
#define MAX_STR 256
int main(void)
{
char sInput[MAX_STR]={0};
int iCnt = 0, iSum = 0;
//char cRe='y';
char* cPtr = NULL;
printf("Input Word\t: ");
fgets(sInput, MAX_STR - 1, stdin);
cPtr=sInput;
while (*cPtr != '\0') {
if (*cPtr >= 'a' && *cPtr <= 'z') {
iSum += *cPtr - 'a' + 1;
}
else if (*cPtr >= 'A' && *cPtr <= 'Z') {
iSum += *cPtr - 'A' + 1;
}
cPtr++;
}
printf("Sum of Word\t: %d\n", iSum);
return 0;
}
Output
'C\C++' 카테고리의 다른 글
소수 구하기 2 (0) | 2022.02.18 |
---|---|
소수 구하기 (0) | 2022.02.17 |
Array & Pointer 예제 (0) | 2022.02.16 |
2D Array Sum (0) | 2022.02.14 |
string ex01 (0) | 2022.02.14 |