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 )
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: