-4

suppose we are given input number as 1234 then after right circular shift we should get 4123 as output. I tried solving it using MOD operator but it didnt work.

Gaurav
  • 1
  • 1
  • 4
    No code, no actual output - how do you expect us to find the bug in your code? – MSalters Apr 15 '16 at 14:31
  • 3
    Perhaps your question should show what you tried, what you expected to happen, what actually happened, and finally ask a question about what you don't understand about the difference between what happened and what you expected. – James Adkison Apr 15 '16 at 14:31
  • 1
    The suggested duplicate appears to be about binary shift, while this question appears to be about shifting in base 10, so I don't think the answers in the duplicate are of much use and I don't think it's an appropriate duplicate. That said, I voted to close this question as off topic because of lack of mcve and I'm not voting to reopen until the question has been improved. – eerorika Apr 15 '16 at 14:40
  • The question should be closed, but not as a dupe - it is different from the linked answer. Let's keep it consistent. @user2079303, it's open now, so you can join me and vote to close it with a proper reason. – SergeyA Apr 15 '16 at 14:50
  • @SergeyA I can't vote because "[I] voted to close this question 22 mins ago" – eerorika Apr 15 '16 at 14:55
  • 1
    What's wrong with data structures? – Raymond Chen Apr 15 '16 at 15:09
  • There is no MOD operator. Show some code. – Pete Becker Apr 15 '16 at 16:20

2 Answers2

1

Your task can solved this way:

unsigned int CSWR(unsigned int i) {
    unsigned int rem = i % 10;
    unsigned int temp = i / 10;
    i = temp;
    if (!i)
        return rem;

    for(rem *=10;i/=10;rem *= 10);
    return rem + temp;
}
Anatoly
  • 21
  • 3
1

Or, this way:

int a = 1234;
int result = (a/10) + (a%10)*pow(10,(int)log10(a));
shrike
  • 4,449
  • 2
  • 22
  • 38