My next assignment was to take in a positive integer of up to 10 digits (that was the curveball) and display them vertically from right to left. It wasn’t bad, except for the 10 digit part. Seems like type int runs out of steam somewhere between 9 and 10 digits and since I’m using modulus, int seems like the logical choice. I found long long int which solved my problem but I have doubts as to if that is what my teacher is looking for, because we haven’t learned that yet (never heard of it until today). My question, is there a better or another way to do this? Here is the code:
This program runs and works fine, just curious about a different method, although long long int seems like a good way to get around my issue.Code:#include <stdio.h>
int main (void)
{
int loop, rem;
long long int number, max;
max = 9999999999;
printf ("Please enter a number of 10 digits or less: ");
scanf ("%lld", &number);
if (number == 0)
{
printf ("%lld\n", number);
}
else
{
while (number > max || number < 0)
{
printf ("Your number is either too large or negative, please try again: ");
scanf ("%lld", &number);
}
for (loop = 0; number != 0; loop++)
{
rem = number % 10;
number = number / 10;
printf ("%d\n", rem);
}
}
}