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 "<
{
r[i]=n%8;
n=n/8;
}
i--;
for(;i>=0;i--)
cout<
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
/*
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));
}
}
#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();
}
int iInteger ={ ... some value ... };
printf("%o\n", iInteger);
printf ("%d is %o in octal\n", x, x);
The last number in the world is air
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.
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
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
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.
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.
Use %o
You can multiply the numerator and the denominator of a fraction by any non-zero integer to get an equivalent fraction.
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.
To find an integer you ask your teacher.
Multiply the numerator and the denominator by the same integer.
418 is an integer and not a fraction. So division is not going to help.
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.
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.
Pick any non-zero integer, n. Then A*n and B*n are an equivalent ratio.
I dont freakin know, use a god damned calculator, I'm not Einstein mother fu**er.
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
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.