Reversed Integer Using Arrays, My friend told me its to complicated
The assignment everyone has done before..lol...reversing digits. How do i make my code more simple (as my friend stated)?
Trying to write a program that reverses the digits in an integer. Assuming that the max value of the integer is 99999. And using arrays to solve the problem.
For example if integer:
0 was entered, output is 0
10 was entered, output is 1
12 was entered, output is 21
123 was entered, output is 321
7600 was entered, output is 67
8015 was entered, output is 5108
90000 was entered, output is 9
here is my code:
Code:
#include <stdio.h>
#include <math.h>
int main()
{
int intnumber, condition, remainder;
int counter = 0, i = 0, j = 0, counter1 = 0;
int reverseint[99999];
printf("Enter an integer number: ");
scanf_s("%d", &intnumber);
condition = intnumber;
while (condition > 0)
{
condition = condition /10;
counter = counter + 1;
counter1 = counter1 + 1;
}
counter = counter - 1;
printf("The number in reverse: ");
while (counter >= 0)
{
remainder = intnumber % (int) pow(10, counter);
intnumber = intnumber/(int) pow(10,counter);
reverseint[i] = intnumber;
i++;
intnumber = remainder;
counter = counter - 1;
}
for(j=counter1-1;j >= 0;j--)
{
printf("%d ", reverseint[j]);
printf("\n");
}
}
Re: Reversed Integer Using Arrays, My friend told me its to complicated
I found out that, I can't use printf but instead use couts.
I'm in a beginner level's C++ class and my teacher also wants it more simpler..aha
said i can't use scanf_s, pow, and strings!?!?!