Write a program to receive an integer and find its octal
equivalent?

Answers were Sorted based on User's Feedback



Write a program to receive an integer and find its octal equivalent?..

Answer / nagarajanselvaraj

#include<stdio.h>
void main()
{
int num,ocnum=1,foct=0,temp;
printf("\nEnter an integer = ");
scanf("%d",&num);
while(num>=8) //loop for converting decimal to octal
{
temp=num%8;
num=num/8;
ocnum=(ocnum*10)+temp;
}
ocnum=(ocnum*10)+num; //number is in reverse
while(ocnum!=1) //loop for reversing the octal result
{
temp=ocnum%10;
ocnum=ocnum/10;
foct=(foct*10)+temp;
}
printf("\nThe octal equivalent of %d\n",foct);
}

Is This Answer Correct ?    89 Yes 57 No

Write a program to receive an integer and find its octal equivalent?..

Answer / a jha

#include <stdio.h>
#include <conio.h>


int main()
{
int n,i=0,j=1,k=0;

printf("Enter the number:
");
scanf("%d",&n);
while(n !=0)
{
i = (n%8)*j;
n = n/8;
j= j*10;
k = k+i;

}


printf("%d",k);



getch();
return 0;
}

Is This Answer Correct ?    25 Yes 9 No

Write a program to receive an integer and find its octal equivalent?..

Answer / mayur anklekar

#include <stdio.h>
//Writer:Mayur Anklekar
int main()
{
int a,mod=0,b=0,u=1,c=1;
printf("Enter the Number:");
scanf("%d",&a);
while(a!=0)
{
mod=a%8;
u=mod*c;
b=b+u;
a=a/8;
c=c*10;
}
printf("Octal Equivalent=%d",b);
}

Happy Coding!!

Is This Answer Correct ?    7 Yes 3 No

Write a program to receive an integer and find its octal equivalent?..

Answer / priyankar kumar

Write a program to find the octal equivalent of the entered number
#include<stdio.h>
main()
{
int n,n1=0,n2=0,n3,a,b,c;
printf("enter the number in decimal
");
scanf("%d",&n);
c=n+1;
if((n%8)>0)
{
while(n>0)
{
a=n%8;
n1=n1*10+a;
n=n/8;
}
while(n1>0)
{
b=n1%10;
n2=n2*10+b;
n1=n1/10;
}
printf("octal equivalent=%d",n2);
}
else
{
while(c>0)
{
a=c%8;
n1=n1*10+a;
c=c/8;
}
while(n1>0)
{
b=n1%10;
n2=n2*10+b;
n1=n1/10;
}
n3=n2-1;
printf("octal number=%d
",n3);
}
getch();
}

Is This Answer Correct ?    3 Yes 5 No

Write a program to receive an integer and find its octal equivalent?..

Answer / gurpreet singh

#include<stdio.h>

int main()
{
int n,m,o=0,t=10;
printf("

Enter any integer value

");
scanf("%d",&n);

while(n>0)
{

m=n%8;
n=n/8;

o=o+(m*t);
t=t*10;

}
printf("

octal number=%d

",o/10);

}

Is This Answer Correct ?    1 Yes 3 No

Write a program to receive an integer and find its octal equivalent?..

Answer / priyankar kumar

//Write a program to find the octal equivalent of the entered number;
#include<stdio.h>
main()
{
int n,n1=0,n2=0,n3=0,n4=0,n5,a,b,c,d;
printf("enter the number in decimal
");
scanf("%d",&n);
c=n-1;
d=n+1;
if((n%8)>0)
{
while(n>0)
{
a=n%8;
n1=n1*10+a;
n=n/8;
}
n4=n1;
while(n1>0)
{
b=n1%10;
n2=n2*10+b;
n1=n1/10;
}
printf("octal equivalent=%d",n2);
}
else
{
while(c>0)
{
a=c%8;
n1=n1*10+a;
c=c/8;
}
while(n1>0)
{
b=n1%10;
n2=n2*10+b;
n1=n1/10;
}
while(d>0)
{
a= d%8;
n3=n3*10+a;
d=d/8;
}
while(n3>0)
{
b=n3%10;
n4=n4*10+b;
n3=n3/10;
}
n5=n2+(n4-n2)-1;
printf("octal number=%d
",n5);
}
getch();
}

Is This Answer Correct ?    2 Yes 6 No

Write a program to receive an integer and find its octal equivalent?..

Answer / mrityunjay barman

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int n,i=0,r,s=0;
printf("enter the number\n");
scanf("%d",&n);
while(n>0)
{r=n%8;
s=s+n*(pow(10,i));
n=n\8;
i++;
}
printf("the octal number =%d",s);
getch();
}

Is This Answer Correct ?    15 Yes 31 No

Post New Answer

More C Code Interview Questions

#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }

0 Answers   Student,


4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }

2 Answers   Broadridge,


write a c program to Reverse a given string using string function and also without string function

1 Answers  


/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }

4 Answers  


how to check whether a linked list is circular.

11 Answers   Microsoft,






how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!

8 Answers   GATE,


Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2])

1 Answers  


pls anyone can help me to write a code to print the values in words for any value.Example:1034 to print as "one thousand and thirty four only"

2 Answers  


main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above

2 Answers   HCL,


How to reverse a String without using C functions ?

33 Answers   Matrix, TCS, Wipro,


What is full form of PEPSI

0 Answers  


Write a program to check whether the number is prime and also check if it there i n fibonacci series, then return true otherwise return false

1 Answers   Cognizant, lenovo,


Categories