C Program To Convert Decimal to Binary Decimal to Octal

#include<stdio.h>
#include<conio.h>
void main()
{
int bin[10],n,num,i,dig,j,opt;
char c;
clrscr();
do
{
 printf("***Menu***\n1.Decimal to Binary\n2.Decimal to Octal\n3.Exit");
 printf("\nEnter Ur choice: ");
 scanf("%d",&opt);
 switch(opt)
 {
 case 1: printf("Enter Decimal number: ");
 scanf("%d",&n);
 num=n;
 i=0;
 while(n>0)
 {
 dig=n%2;
 bin[i]=dig;
 n=n/2;
 i++;
 }   printf("Equivalent Binary of Decimal %d is :",num);
  for(j=i-1;j>=0;j--)
  printf(" %d",bin[j]);

break;
case 2: printf("Enter Decimal number: ");
 scanf("%d",&n);
 i=0;
 num=n;
 while(n>0)
 {
 dig=n%8;
 bin[i]=dig;
 n=n/8;
 i++;
 }   printf("Equivalent Octal of Decimal %d is :",num);
  for(j=i-1;j>=0;j--)
  printf(" %d",bin[j]);

break;
case 3: exit(0);
 break;
default: printf("*****Invalid Choice*****");
}
printf("\nDo U want to Continue (y/n): ");
fflush(stdin);
c=getchar();
}while(c=='Y'||c=='y');
getch();
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment