Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "string.h"
- int main(void) {
- char charNumber[30], resultSoNguyen[30], resultThapPhan[30];
- int iLoop, iLength, iResult, iForThapPhan;
- printf("Nhap vao mot so thap phan: ");
- scanf("%s", charNumber);
- iLength = (int) strlen(charNumber);
- for (iLoop = 0; iLoop < iLength; iLoop++) {
- resultSoNguyen[iLoop] = charNumber[iLoop];
- if (charNumber[iLoop + 1] == ',') {
- iResult = iLoop;
- break;
- }
- if (charNumber[iLoop + 1] == '\0') {
- iResult = iLoop;
- break;
- }
- }
- resultSoNguyen[iResult + 1] = '\0';
- iForThapPhan = 0;
- for (iLoop = iResult + 2; iLoop < iLength; iLoop++) {
- resultThapPhan[iForThapPhan] = charNumber[iLoop];
- iForThapPhan++;
- }
- resultThapPhan[iForThapPhan] = '\0';
- if ((int)strlen(resultThapPhan) == 0) {
- resultThapPhan[0] = '0';
- resultThapPhan[1] = '\0';
- }
- printf("So nguyen la: %s.\nPhan thap phan la: %s.\n", resultSoNguyen, resultThapPhan);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement