Write a program to receive an integer and find its octal
equivalent?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
What is the hidden bug with the following statement? assert(val++ != 0);
Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2])
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?
main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4
18 Answers HCL, IBM, Infosys, LG Soft, Satyam,
Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.
what is brs test reply me email me kashifabbas514@gmail.com
what is the output of the below program & why ? #include<stdio.h> void main() { int a=10,b=20,c=30; printf("%d",scanf("%d%d%d",&a,&b,&c)); }
main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }
what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }
posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come
Is it possible to type a name in command line without ant quotes?
why array index always strats wuth zero?