Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include<string.h>
- void number_system(int N)
- {
- if(N==1){
- int a[10],n,i;
- printf("Desimal To Binary: ");
- scanf("%d",&n);
- for(i=0;n>0;i++)
- {
- a[i]=n%2;
- n=n/2;
- }
- printf("\nBinary of Given Number is=");
- for(i=i-1;i>=0;i--)
- {
- printf("%d",a[i]);
- }
- }
- if(N==2){
- char h[15];
- int i=0,d,k;
- printf("Desimal To Hexadesimal:");
- scanf("%d",&d);
- while(d!=0)
- {
- k=d%16;
- if(k>9)
- h[i]=(char)(k+55);
- else
- h[i]=(char)(k+48);
- d=d/16;
- i++;
- }
- h[i]='\0';
- strrev(h);
- printf("%s",h);
- }
- if(N==3)
- {
- int dec,oct=0,rem,k=1;
- printf("Desimal To Octal:");
- scanf("%d",&dec);
- while(dec!=0)
- {
- rem=dec%8;
- oct=rem*k+oct;
- k=k*10;
- dec=dec/8;
- }
- printf("%d",oct);
- }
- if(N==4)
- {
- int dec=0,bin,base=1,rem,num;
- printf("Binary To Decimal:");
- scanf("%d",&bin);
- while(bin!=0)
- {
- rem=bin%10;
- dec=dec+rem*base;
- bin=bin/10;
- base=base*2;
- }
- printf("%d",dec);
- }
- if(N==5)
- {
- long int bin, hex = 0, i = 1, rem;
- printf("Binary To Hexadesimale: ");
- scanf("%ld", &bin);
- while (bin != 0)
- {
- rem = bin % 10;
- hex = hex + rem * i;
- i = i * 2;
- bin = bin / 10;
- }
- printf("%lX", hex);
- }
- if(N==6)
- {
- }
- }
- int main()
- {
- int N;
- printf("Press any number(1 to 12):");
- scanf("%d",&N);
- number_system(N);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement