0

Hii everyone:)
I have written this code to do conversion between decimal to any base between 2 and 26....
But this is not working properly
ca any one help me:confused

#include<iostream.h>
#include<conio.h>

void conversion(int no,int base)
{
	int arr[10]={0};
	int i=0;
	while(no>0)
	{
		arr[i]=no%base;
		i++;
		no=no/base;

	}
	for(int j=i;j>=0;j--)
		cout<<arr[j];
}
void conversionGreater(int no,int base)
{
	int arr[20]={0};
	int i=0,j=0;
	char a='A';

	while(no>0)
	{
		arr[i]=no%base;
		i++;
		no=no/base;

		if(no>=10)
		{
			j=no%base;

			for(int k=0;k<j;k++)
				arr[i]=a+k;
			i++;
			no=no/base;
		}

	}
	for(int l=i;l>=0;l--)
		cout<<arr[l];
}
void main()
{
	clrscr();
	int base=16;
	int no=2600;
	if(base >=2 && base<=9)
		conversion(no,base);
	else if(base >=11 && base<=26)
		conversionGreater(no,base);
	getch();
}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Sky Diploma
0
if(no>=10)
		{
			j=no%base;

			for(int k=0;k<j;k++)
				arr[i]=a+k;
			i++;
			no=no/base;
		}

I would like to know what are you trying to do here. FIrstly you are converting the alphabet character 'A' into an int. ANd then secondly after the for loop is done it would just add (a+j) in the end.

Secondly could you post an example of the input and the required output.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.