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> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

2 Answers   CNSI,


Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.

3 Answers   Wipro,


main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

1 Answers  


#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); }

2 Answers  






main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }

2 Answers  


main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024

2 Answers   HCL,


3) Int Matrix of certain size was given, We had few valu= es in it like this. =97=97=97=97=97=97=97=97=97=97=97 1 = | 4 | | 5 | &= nbsp; | 45 =97=97=97=97=97=97=97=97=97=97=97 &n= bsp; | 3 | 3 | 5 | = | 4 =97=97=97=97=97=97=97=97=97=97=97 34 |&nbs= p; 3 | 3 | | 12 | &= nbsp; =97=97=97=97=97=97=97=97=97=97=97 3 | &nbs= p; | 3 | 4 | = | 3 =97=97=97=97=97=97=97=97=97=97=97 3 | = ; | | | = ; 3 | =97=97=97=97=97=97=97=97=97=97=97 &= nbsp; | | 4 | = ; | 4 | 3 We w= ere supposed to move back all the spaces in it at the end. Note: = If implemented this prog using recursion, would get higher preference.

0 Answers   RoboSoft,


main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }

2 Answers  


write a c-program to display the time using FOR loop

3 Answers   HCL,


why java is platform independent?

13 Answers   Wipro,


main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O

4 Answers   HCL,


Categories