0% found this document useful (0 votes)
170 views1 page

Base Conversion Program in C++

This C++ program takes a base and number as input from the user. It then checks if the base is between 2 and 10. If so, it uses a do-while loop to iterate through each digit of the number, calculate its value in the given base using exponentials, and add it to the running sum. After the loop, it displays the sum. If the base is not valid, it displays -1.

Uploaded by

Rish Batheja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views1 page

Base Conversion Program in C++

This C++ program takes a base and number as input from the user. It then checks if the base is between 2 and 10. If so, it uses a do-while loop to iterate through each digit of the number, calculate its value in the given base using exponentials, and add it to the running sum. After the loop, it displays the sum. If the base is not valid, it displays -1.

Uploaded by

Rish Batheja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream.

h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<process.h>
void main()
{
clrscr();
int a,base,x,i,j,k,l,sum;
long num;
sum=0;
cout<<"Enter the base and number: ";
cin>>base>>num;
j=0;
if(base>=2&&base<=10)
{
do{
a=num%10;
num=num/10;
if(a>=base)
{
cout<<-1;
getch();
exit(0);
}
sum=sum+(a*pow(base,j));
j++;
}while(num!=0);
cout<<sum;
}
else
{
cout<<-1;
}
getch();
}

You might also like