Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************
- * Class: MAGSHIMIM C7 *
- * Week 11 *
- **********************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- #define MAX_LENGTH_OF_INT_NUM 10
- typedef enum BOOL { FALSE, TRUE };
- int lengthOfNum(int inputNum);
- int reverseNum(int inputNum);
- void printProcessedStringNum(int reversedNum, int inputNumLength);
- int main(void) //Main function
- {
- int inputNum = 0, inputNumLength = 0, reversedInputNum = 0;
- inputNum = getInputNum();
- reversedInputNum = reverseNum(inputNum);
- inputNumLength = lengthOfNum(inputNum);
- printProcessedStringNum(reversedInputNum, inputNumLength);
- return 0; //Returning 0
- }
- int getInputNum(void)
- {
- int inputNum = 0;
- printf("Enter num: ");
- scanf_s("%d", &inputNum);
- return inputNum;
- }
- void printProcessedStringNum(int reversedNum, int inputNumLength)
- {
- int i = 0, copyOfNum = 0;
- char stringProcessedNum[MAX_LENGTH_OF_INT_NUM + 1] = { 0 };
- if (reversedNum < 0)
- {
- stringProcessedNum[0] = '-';
- i = 1;
- }
- else if (reversedNum > 0)
- {
- stringProcessedNum[0] = '+';
- i = 1;
- }
- stringProcessedNum[inputNumLength + i] = 0;
- for (i; i < inputNumLength; i++)
- {
- while (copyOfNum != 0)
- {
- stringProcessedNum[i] = (char)(copyOfNum % 10 + 48);
- copyOfNum /= 10;
- }
- }
- printf("string: %s length: %d\n", stringProcessedNum, inputNumLength);
- }
- int lengthOfNum(int inputNum)
- {
- int copyOfNum = 0, inputNumLength = 0;
- copyOfNum = inputNum;
- if (inputNum != 0)
- {
- while (copyOfNum != 0)
- {
- inputNumLength++;
- copyOfNum /= 10;
- }
- }
- else
- {
- inputNumLength = 1;
- }
- return inputNumLength;
- }
- int reverseNum(int inputNum)
- {
- int copyOfNum = 0, reversedNum = 0, remainderOfNum = 0;
- copyOfNum = inputNum;
- while (copyOfNum != 0)
- {
- remainderOfNum = copyOfNum % 10;
- reversedNum = reversedNum * 10 + remainderOfNum;
- copyOfNum /= 10;
- }
- return reversedNum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement