티스토리 뷰
isdigit()
sprintf()
atoi()
----------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "check.h"
/**
* 체크수를 생성하는 기능
*
* @param[in] inputData 입력데이터(숫자)
* @return 체크수
*/
int getCheckNum(int inputData) {
int checkNum = 0;
////////////////////////// ---------------->
int count = 0;
int digit = 0;
int sum = 0;
// 1. 각 자릿수의 수를 곱셈 연산
while(inputData != 0) {
digit = inputData % 10; // 자릿수
count++; // 곱셈에 사용되는 수
sum = sum + digit * count;
inputData = inputData/10;
}
// 2. 체크수 생성
if(sum % count != 0)
checkNum = sum % count;
else
checkNum = sum / count;
/////////////////////////// <--------------
return checkNum;
}
/**
* 새로운 수를 생성하는 기능
*
* @param[in] inputData 입력데이터(숫자)
* @param[in] checkNum 체크수
* @return 새로운 수
*/
int generateNewNum(int inputData, int checkNum) {
int newNum = 0;
////////////////////////// ---------------->
char strNew[10] = {0, };
if (checkNum < 10) {
sprintf(strNew, "%d%d", inputData, checkNum);
}
else {
int n1, n2;
n1 = checkNum / 10;
n2 = checkNum % 10;
if (n1 > n2)
sprintf(strNew, "%d%d%d", n1, inputData, n2);
else
sprintf(strNew, "%d%d%d", n2, inputData, n1);
}
newNum = atoi(strNew);
/////////////////////////// <--------------
return newNum;
}
'Test > C' 카테고리의 다른 글
center number (크기 기준) (0) | 2019.04.28 |
---|---|
2018_2_pad (0) | 2019.04.27 |
MingGW 컴파일러 데이터타입 싸이즈 (0) | 2019.04.07 |
파일 입출력 (0) | 2019.01.07 |
구조체와 공용체 (0) | 2019.01.05 |
- Total
- Today
- Yesterday
- powercli
- 제곱
- insert
- set()
- 변수화
- sysprep
- cloud-init
- 부동없이
- 읽어오기
- 차집합
- dp-2
- Join
- 중복제거
- virt-sysprep
- dp-1
- 대소문자
- exadata
- vmware
- LIST
- 배열
- vmware.powercli
- fromkeys
- EXA
- oracle
- storage
- 정렬
- powershell
- Append
- 스토리지
- 3par
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |