|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
C
DETAILS
Question: How to convert decimal to octal and hexadecimal?
Answer: /*To Convert a Decimal number to Octal and Hexadecimal*/ #include<stdio.h> #include<conio.h> void main() { int m,i,n,z,x,b,c,d[100]; clrscr(); printf("Enter a Number : "); scanf("%d",&n); z=n; b=1; while(n>0) {c=n%8; b=b*10+c; n=n/8;} n=b; b=0; while(n>0) {c=n%10; b=b*10+c; n=n/10;} b=b/10; printf("Octal Value for the given number is : %d
",b); n=z; b=0; i=0; while(n>0) {c=n%16; d[i]=c; n=n/16; x=i++;} printf("Hexadecimal Value for the given number is : "); for(i=x;i>=0;i--) {if(d[i]<10) printf("%d",d[i]); else {m=(d[i]-9)-1; printf("%c",'A'+m);} } getch(); }
|
|
|
Category |
C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7357 users |
Added on |
9/7/2013 |
Views |
68262 |
Rate it! |
|
|
Question:
How to convert decimal to octal and hexadecimal?
Answer:
/*To Convert a Decimal number to Octal and Hexadecimal*/ #include<stdio.h> #include<conio.h> void main() { int m,i,n,z,x,b,c,d[100]; clrscr(); printf("Enter a Number : "); scanf("%d",&n); z=n; b=1; while(n>0) {c=n%8; b=b*10+c; n=n/8;} n=b; b=0; while(n>0) {c=n%10; b=b*10+c; n=n/10;} b=b/10; printf("Octal Value for the given number is : %d
",b); n=z; b=0; i=0; while(n>0) {c=n%16; d[i]=c; n=n/16; x=i++;} printf("Hexadecimal Value for the given number is : "); for(i=x;i>=0;i--) {if(d[i]<10) printf("%d",d[i]); else {m=(d[i]-9)-1; printf("%c",'A'+m);} } getch(); } Source: CoolInterview.com
Answered by: Dinesh babu | Date: 9/17/2008
| Contact Dinesh babu
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
If we want that any wildcard characters in the command line argument should be approxiemately expanded , are we required to make any special provision?if yes, which?
|
View Answer
|
|
How would you obtain the current time and difference between two times?
|
View Answer
|
|
What is a default TCP/IP socket assigned for SQL Server?
|
View Answer
|
|
#include <stdio.h> int main() {
int a=3, b = 5; printf(&a["Ya!Hello! how is this? %s "], &b["junk/super"]); printf(&a["WHAT%c%c%c %c%c %c ! "], 1["this"], 2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);
return 0; }
|
View Answer
|
|
How i can run *.bat or *.cmd file by using system function in c ?
|
View Answer
|
|
Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }
|
View Answer
|
|
Can there be a mouse click and drag function used together to rotate a circle in c?please give which are they?
|
View Answer
|
|
Can there be a mouse click and drag function used in c?
|
View Answer
|
|
Between n+1 and n++ which executes faster or both take the same time to execute?
|
View Answer
|
|
Range of int in is -32768 to 32767 and it occupy 2 byte in memory and char take 1 byte take single char but in java int is 4 byte take value-2,147,483648 to 647 and char occupy 2 byte and also take single variable why not more?`
|
View Answer
|
|
How to connect a database (MS Access) to Borland C? Please give me step by step coding.
|
View Answer
|
|
To which numbering system can the binary number 1101100100111100 be easily converted to?
|
View Answer
|
|
What are bit fields? What is the use of bit fields in a structure declaration?
|
View Answer
|
|
What are enumerations?
|
View Answer
|
|
Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]?
|
View Answer
|
|
What is the use of typedef?
|
View Answer
|
|
Which mistakes are called as token error?
|
View Answer
|
|
What is the function of % using in formatted string.
|
View Answer
|
|
How to print the names of employees or students in alphabetical order using C programming?
|
View Answer
|
|
How should i rate on the basis of the basis of the scenario the insertion sort , bubble sort , Quick Sort?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All C Interview Questions & Answers - Exam Mode /
Learning Mode
|