Write a program to receive an integer and find it's octal
equivalent.
How can i do with using while loop.

Answers were Sorted based on User's Feedback



Write a program to receive an integer and find it's octal equivalent. How can i do with using..

Answer / mithun shrivastav

#include<stdio.h>

void main()
{
int n,sum = 0,rev = 0;
print("\nEnter an Integer No. : ");
scanf("%d", &n);

while(n>0)
{
sum = sum * 10 + n%8;
n = n/8;
}

while(sum > 0)
{
rev = rev*10 + sum%10;
sum = sum/10;
}

printf("Octal Equivalent = ", rev);

getch();
}

Is This Answer Correct ?    19 Yes 16 No

Write a program to receive an integer and find it's octal equivalent. How can i do with using..

Answer / nitin sokhal

This program is Correct

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More C Code Interview Questions

&#8206;#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }

2 Answers  


How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”)

4 Answers   HCL,


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


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

2 Answers   HCL,


hello sir,is there any function in C that can calculate number of digits in an int type variable,suppose:int a=123; 3 digits in a.what ll b answer?

6 Answers  






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,


main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }

1 Answers  


main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }

2 Answers  


int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }

1 Answers  


main() { int i=5,j=6,z; printf("%d",i+++j); }

2 Answers  


#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }

1 Answers  


#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }

1 Answers  


Categories