C coding a rotate function (help me pleasee)

Joined
Dec 25, 2022
Messages
1
Reaction score
0
hello everyone ..
i would really appriciate it if someone would help me with this question..
i upload here the code i wrote, its not really solving anything (i get an really odd outputs),but i would like that someone will explain to me what am i doing wrong ( even if its probably everything :( )..
so the question is to write an efficiant function that turn the digites from right to left (the user choose the amount of spins he would want to do on a function )
C:
#include<stdio.h>
#include<math.h>
int rotateNumber(int number, int spins)
{
    int reminder, answer = 0, num =0;
    for (int i = spins;i >=0; i--)
    {
            reminder = number % 10;
            answer = answer+reminder *pow(10,num-1);
            

    }
    return answer;
}

int numberLength(int num)
{
    int number = 0, spins = 0;
    while (number != 0)
    {
        {
            num = number / 10;
            num++;
        }
        return num;
    }
    if (spins % num == 0)
    {
        printf("%d", number);
    }
    return number;
}
inputIntNonNegative()
{
    int number = 0,spins=0;
    scanf_s("%d", &number);
    while (number < 0)
    {
        printf("Enter a positive number: ");
        scanf_s("%d", &number);
    }
    return number;
    return spins;
}
void main()
{
    int number = 0, spins = 0, answer = 0;
    printf("\nplease enter the number: ");
    number = inputIntNonNegative();
    printf("please enter the amount of spins: ");
    spins = inputIntNonNegative();
    answer = rotateNumber(number, spins);
    printf("The number %d after %d spins is: %d\n", number, spins, answer);
}
 
Last edited:
Joined
Dec 21, 2022
Messages
28
Reaction score
4
Can you give some example inputs and their results, e.g. if i have the number
123456 and then what shall be the result for spin 1 or spin 2 or spin 3?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,708
Messages
2,569,346
Members
44,650
Latest member
LuckyVivo

Latest Threads

Top