I downloaded this code from some site after a search. As you can see it has a limit(295600127). Why? is there a mistake in the code. . anyways I want to make it work correctly. With someones help of course. Basically explail what is going on below the first return 0;
Code:
/*295600127currentlimit*/
#include <stdio.h>
#include <math.h>
int convertDecimalToOctal(int decimalNumber);
int main()
{
int decimalNumber;
printf("Enter a decimal number: ");
scanf("%d", &decimalNumber);
printf("%d in decimal = %d in octal", decimalNumber, convertDecimalToOctal(decimalNumber));
return 0;
}
int convertDecimalToOctal(int decimalNumber)
{
int octalNumber = 0, i = 1;
while (decimalNumber != 0)
{
octalNumber += (decimalNumber % 8) * i;
decimalNumber /= 8;
i *= 10;
}
return octalNumber;
}
Just to prove i'm a beginner this is my own dec/oct converter:
It would only do up 2147483647 until I figured out to unsign my int's
I guess I can't wordwrap my code huh?
Code:
/*decimal_octal_converter*/
#include <stdio.h>
/*---------------*/
unsigned int dec, oct;
int main(void)
{
printf("Enter a number between 0 and 4294967295: ");
scanf ("%d", &dec);
printf("Octal value: %d%d%d%d%d%d%d%d%d%d%d", dec/(8*8*8*8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8*8*8*8)/(8*8*8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8*8*8)/(8*8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8*8)/(8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8)/(8*8*8*8*8*8), dec%(8*8*8*8*8*8)/(8*8*8*8*8), dec%(8*8*8*8*8)/(8*8*8*8), dec%(8*8*8*8)/(8*8*8), dec%(8*8*8)/(8*8), dec%(8*8*8)%(8*8)/8, dec%8);
return 0;
}
And this is the easiest one:
It took me a while to learn that %o means substitute the decimal number with it's equivalent octal value. In fact if yoy replace the o with an x it wil give the hex value. I couldn't figure out how just modulus%ozero could do all that figuring. Obviously I now know that's not a zero but an "o".
Code:
/* C Program to Convert Decimal to Octal Number */
#include <stdio.h>
int main()
{
int number;
printf("\n Please Enter the Number You want to Convert : ");
scanf("%d", &number);
printf("\n Octal Number of a Given Number = %o", number);
return 0;
}