Dear All,
I have written a program which converts an input decimal number into any number in a base between 2 and 36. Below is my program:
I am getting correct values of newbase and ndigit but am unable to print the value of the converted output stored in newrep array. For example if I enter input number as 15 and base as 8 then I should get 17 as output. Kindly help me out to print the value of the output array. Thank you.Code:#include<stdio.h> #include<stdlib.h> int main() { int newbase,n,i,ascii,ndigit=0,q,r,zero; char newrep[100]; printf("Enter the number to be converted"); scanf("%d",&n); printf("Enter the base between 2 and 36 to which the number is to be converted"); scanf("%d",&newbase); zero=48; q=n; ndigit=0; while(q!=0) { r=q%newbase; ndigit+=1; ascii=zero+r; if(ascii>57) { ascii=ascii+7; } newrep[ndigit]=(char)ascii; q=q/newbase; } printf("Base %d representation of %d is\n",newbase,n); for(i=ndigit;i<1;i--) { printf("%s",newrep[ndigit]); } system("pause"); return 0; }



1Likes
LinkBack URL
About LinkBacks



