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 |
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }
program to find magic aquare using array
why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?
main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }
main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }
How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”)
What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }
Give a one-line C expression to test whether a number is a power of 2.
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
What are the files which are automatically opened when a C file is executed?
Write a program that produces these three columns sequence nos. using loop statement Sequence nos. Squared Squared + 5 1 1 6 2 4 9 3 9 14 4 16 21 5 25 30