Program:
// #include<conio.h>
#include<stdio.h>
void main()
{
int b,n,i,r,digit,p,count=0;
char a[100];// clrscr();
printf("\nEnter the decimal number:\n");
scanf("%d",&n);
printf("\nEnter the base to be converted:\n");
scanf("%d",&b);
p=n;
do
{
r=p%b;
digit='0'+r;
if(digit>'9')
digit=digit+7;
a[count]=digit;
count++;
p=p/b;
} while(p!=0);
printf("\nbase %d equivalent of num %d is ",b,n);
for(i=count-1;i>=0;--i)
printf("%c",a[i]);
printf(".\n");
// getch();
}
Output:
nn@linuxmint ~ $ gcc c16.c
nn@linuxmint ~ $ ./a.out
Enter the decimal number:
10
Enter the base to be converted:
2
base 2 equivalent of num 10 is 1010.
nn@linuxmint ~ $ ./a.out
Enter the decimal number:
10
Enter the base to be converted:
8
base 8 equivalent of num 10 is 12.
nn@linuxmint ~ $ ./a.out
Enter the decimal number:
15
Enter the base to be converted:
16
base 16 equivalent of num 15 is F.
nn@linuxmint ~ $
// #include<conio.h>
#include<stdio.h>
void main()
{
int b,n,i,r,digit,p,count=0;
char a[100];// clrscr();
printf("\nEnter the decimal number:\n");
scanf("%d",&n);
printf("\nEnter the base to be converted:\n");
scanf("%d",&b);
p=n;
do
{
r=p%b;
digit='0'+r;
if(digit>'9')
digit=digit+7;
a[count]=digit;
count++;
p=p/b;
} while(p!=0);
printf("\nbase %d equivalent of num %d is ",b,n);
for(i=count-1;i>=0;--i)
printf("%c",a[i]);
printf(".\n");
// getch();
}
Output:
nn@linuxmint ~ $ gcc c16.c
nn@linuxmint ~ $ ./a.out
Enter the decimal number:
10
Enter the base to be converted:
2
base 2 equivalent of num 10 is 1010.
nn@linuxmint ~ $ ./a.out
Enter the decimal number:
10
Enter the base to be converted:
8
base 8 equivalent of num 10 is 12.
nn@linuxmint ~ $ ./a.out
Enter the decimal number:
15
Enter the base to be converted:
16
base 16 equivalent of num 15 is F.
nn@linuxmint ~ $
genus!!! Thanks a lot.
ReplyDeletewhy u have done
ReplyDeleteif(digit>'9')
digit=digit+7;
@Nishant Kumar
ReplyDeleteBecause after 9 you have 7 ASCII character in between 9 ans A and you have to use A after 9 instead to 10(not in case of base 10/decimal).
Wrong output
ReplyDeletesame
Deletenice Post! Thank you for sharing this good article.
ReplyDeletePython Training in Electronic City
Python Course in Electronic City
This post is good enough to make somebody understand this amazing thing, and I’m sure everyone will appreciate this interesting things. Hex To Decimal
ReplyDeleteThanks for your informative article,Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
ReplyDeleteangular js training in chennai
angular js training in porur
full stack training in chennai
full stack training in porur
php training in chennai
php training in porur
photoshop training in chennai
photoshop training in porur
Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
ReplyDeletehadoop training in chennai
hadoop training in tambaram
salesforce training in chennai
salesforce training in tambaram
c and c plus plus course in chennai
c and c plus plus course in tambaram
machine learning training in chennai
machine learning training in tambaram
Thank you so much for sharing these amazing tips. I must say you are an incredible writer, I love the way that you describe the things. Please keep sharing.
ReplyDeletedata science training in chennai
data science training in velachery
android training in chennai
android training in velachery
devops training in chennai
devops training in velachery
artificial intelligence training in chennai
artificial intelligence training in velachery
Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
ReplyDeletehadoop training in chennai
hadoop training in annanagar
salesforce training in chennai
salesforce training in annanagar
c and c plus plus course in chennai
c and c plus plus course in annanagar
machine learning training in chennai
machine learning training in annanagar
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
ReplyDeleteweb designing training in chennai
web designing training in omr
digital marketing training in chennai
digital marketing training in omr
rpa training in chennai
rpa training in omr
tally training in chennai
tally training in omr