Originally Posted by

**aGerman**
There's more than one way to skin a cat. Of course it is possible to solve it without additional variables. Just use different factors to move your digits to the right position in the loop. You could make the factors depend on the current value of your diviser variable using if-else or switch-case.

This is how I solved it. I am not sure if this is how it was supposed to be done. I am looking more for validation if I was on the right path or critique. Please let me know.

Code:

int main(void)
{
int number,newNumber = 0,remainder,diviser = 1000;
printf("%s","Enter a four digit number: ");
scanf("%d",&remainder);
while(remainder != 0) {
number = remainder / diviser;
remainder %= diviser;
newNumber += ((number + 7) % 10) * diviser;
diviser /= 10;
}
printf("%s%d\n","New formed number: ",newNumber);
//swap of the digits
remainder = newNumber % 100;
number = newNumber / 100;
remainder = remainder * 100 + number;
if (remainder < 1000) {
if(remainder < 100){
printf("%s%d","Encrypted number is : 00",remainder);
}else {
printf("\n%s%d","Encrypted number: 0",remainder);
}
}else {
printf("\n%s%d","Encrypted number: ",remainder);
}
return 0;
}