Files
college-C/1/ex2_2.c
2022-02-25 15:33:16 +02:00

54 lines
1.4 KiB
C

#include <stdio.h>
#define TEN 10
#define ZERO 0
//---------------------------------------------------------------------------------------
// Exercise 2_2
// ------------
//
// General : The program change order digits - reverse order.
//
// Input : Number with 4 digits.
//
// Process : The program take the digits from right to left and multiplier the digit
// by 10.
//
// Output : Same number like input just reverse order.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 09.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
short num,
temp,
result = ZERO;
printf("Enter number with 4 digits: ");
scanf("%hd", &num);
// Take the first digit from right to left and add to result
temp = num / TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
// Multiplie the result by 10
result *= TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
result *= TEN;
result += num - (temp * TEN);
num = temp;
temp = num / TEN;
result *= TEN;
result += num - (temp * TEN);
printf("%hd\n", result);
}