answersLogoWhite

0


Best Answer

void Decimal_to_Octal()
{
int n,r[10],i;
cout<<"Enter a number to find it's octal equivalent";
cin>>n;
cout<<"The octal equivalent of "<for(i=0;n!=0;i++)
{
r[i]=n%8;
n=n/8;
}
i--;
for(;i>=0;i--)
cout<count<}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

In programming code you can write numbers in binary, decimal, octal, hex and maybe even other base number systems if supported.

Before jumping into a program that actually can convert your inputted number from decimal to octal, we should look how it is done manually.

Decimal number: 345

Divide 345 by 8:

345 / 8 = [43] reminder = 1; 1 becomes LSD(Least Significant Digit), the digit which will be at the end of the number;

Now we need to divide 43 by 8:

43 / 8 = [5] reminder = 3;

Now we need to divide 5 by 8;

5 / 8 = [0] reminder = 5; 5 becomes MSD(Most Significant Digit), the digit which will be at the beginning of the number;

Now 345 in decimal is equal 531 in octal.

Here is a program that works using this method:

#include

#include

int arrToInt(int nums[], int cnt);

int main()

{

int num;

int cnt = 0;

int nums[100];

printf("Enter the number in decimal: ");

scanf("%d", &num);

while (num != 0)

{

/* we save all reminders in the array */

nums[cnt++] = num % 8;

num = num / 8;

}

printf("Number in octal: %d\n", arrToInt(nums, cnt));

return 0;

getch();

}

int arrToInt(int nums[], int cnt)

{

int tmp = 0;

for (cnt = cnt - 1; cnt >= 0; cnt--)

{

tmp += nums[cnt] * pow(10, cnt);

}

return tmp;

}

Testing:

Enter the number in decimal: 0

Number in octal: 0

Enter the number in decimal: 7

Number in octal: 7

Enter the number in decimal: 8

Number in octal: 10

Enter the number in decimal: 345

Number in octal: 531

Enter the number in decimal: 264

Number in octal: 410

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

/*

Program to convert the given number into binary,octal and deciaml

*/

import java.io.*;

class Main

{

public static void main(String agrs[])

{

int a=90;

System.out.println("\nGiven number is "+a);

System.out.println("\nThe Binary equivalent of ""+a+"" is "+Integer.toString(a,2));

System.out.println("The Hexadecimal equivalent of ""+a+" is "+Integer.toString(a,16));

System.out.println("The Octal equivalent of ""+a+"" is "+Integer.toString(a,8));

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

void main()

{

unsigned int n;

clrscr();

printf("\n\tEnter the number : ");

scanf("%u",&n);

printf("\n\tThe input integer (in decimal) = %u\n",n);

printf("\n\tThe input integer (in octadecimal) = %o\n",n);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

int iInteger ={ ... some value ... };

printf("%o\n", iInteger);

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

printf ("%d is %o in octal\n", x, x);

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The last number in the world is air

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the c program to find the octal equivalent of an integer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


How convert octal to binary?

If necessary, pad the value with zeroes so the number of bits is an exact multiple of 3. Then divide the binary value into groups of 3 bits. Convert each group to its corresponding octal digit as follows: Bin = Oct 000 = 0 001 = 1 010 = 2 011 = 3 100 = 4 101 = 5 110 = 6 111 = 7 Example 1: 16-bit value: 1011101101100011 3-bit groupings: (00)1 011 101 101 100 011 Octal digits: 1 3 5 4 3 Octal value: 13543 Example 2: 24-bit value: 010111011010010101011010 3-bit groupings: 010 111 011 010 010 101 011 010 Octal digits: 2 7 3 2 2 5 3 2 Octal value: 27322532


Write a program to check whether the number is divisible by 3 or not by using the?

I assume you mean is an if the number is an integer multiple of 3i am unfamiliar with C but the theory would be,find if a is integer multiple of 3b=a/3b==round(b).if 1 "yes"else "no"this is an inefficiency way but will get the job done


How do you find repeated integer number in the array in java program?

The most simpliest way is to use a nested loop. However this runs in O(N*N) time. For small arrays, this should be sufficient.


How do you write a program to find number of zeros for the given number in c program?

Assuming the number is represented by a decimal integer, initialise a counter to zero, then repeatedly divide the number by 10 and until the number is zero. After each division, examine the remainder. Each time the remainder is zero, increment the counter. If the number is represented by a decimal float, repeatedly multiply by 10 until the value is an integer, then perform the previous algorithm.

Related questions

Wrie a program to receive an integer and find its octal equivalant?

Use %o


How do you multiply to find an equivalent fraction?

You can multiply the numerator and the denominator of a fraction by any non-zero integer to get an equivalent fraction.


How to find equivalent ratios?

Suppose you are given the ratio X/Y.To find an equivalent ration, take ANY positive integer, k. Then (k*X)/(k*Y) is an equivalent ratio.Strictly speaking, k need not be a positive integer: it need not even be a real number. All that is required is that it is not 0.


How do you find an integer?

To find an integer you ask your teacher.


How can you use multiplication to find an equivalent fraction 1 over 3?

Multiply the numerator and the denominator by the same integer.


What is division to find equivalent fraction of 418 math?

418 is an integer and not a fraction. So division is not going to help.


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


How do you write 0.19 as an equivalent fraction?

0.19 = 19/100 as a fraction. To find other equivalent fractions you simply multiply the numerator and denominator by the same non-zero integer.


How would you scale up the ratio A boys to B girls to find equivalent ratios?

Pick any non-zero integer, n. Then A*n and B*n are an equivalent ratio.


Why you can not find binary number from any octal number by dividing the octal number by 2?

I dont freakin know, use a god damned calculator, I'm not Einstein mother fu**er.


How Do you find Equivalent fractions and show a example?

Suppose you have a fraction such as 3/7.To find an equivalent fraction, think of any non-zero integer. How about 6?Multiply the top and the bottom of your original fraction by this number to get an equivalent fraction. So3/7 = (3*6)/(7*6) = 18/42Suppose you have a fraction such as 3/7.To find an equivalent fraction, think of any non-zero integer. How about 6?Multiply the top and the bottom of your original fraction by this number to get an equivalent fraction. So3/7 = (3*6)/(7*6) = 18/42Suppose you have a fraction such as 3/7.To find an equivalent fraction, think of any non-zero integer. How about 6?Multiply the top and the bottom of your original fraction by this number to get an equivalent fraction. So3/7 = (3*6)/(7*6) = 18/42Suppose you have a fraction such as 3/7.To find an equivalent fraction, think of any non-zero integer. How about 6?Multiply the top and the bottom of your original fraction by this number to get an equivalent fraction. So3/7 = (3*6)/(7*6) = 18/42


How do you find the equivalent?

Multiply or divide both the numerator (top) and the denominator (bottom) of the ratio or fraction by any non-zero integer or divide both by any common factor. You will have an equivalent rate.