C Code 28 _ Convert a Base 17 number to a Decimal number[TCS NQT Programming Question]
Given a maximum of 4 digit to the base 17,(A -> 10 , B -> 11 , C -> 12 , D -> 13 , E -> 14 , F ->15 , G -> 16 ) as Input , output is a decimal value.
Example :
input : 1A
output : 27
solving: A means 10 , so (10 * 17 ^ 0) + (1 * 17 ^ 1) = 27
simillarly,
input : 1B2
output : 478
Solving : B means 11 , so (2 * 17 ^ 0) + (11 * 17 ^ 1) + (1 * 17 ^ 2) = 478
Program:
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
char
a[20];
int
i,n,l,j=0,sum=0;
printf("\nEnter
the Input : ");
scanf("%s",a);
l=strlen(a);
for(i=l-1;i>=0;i--)
{
if(a[i]>=65&&a[i]<=90)
{
n=a[i]-65+10;
}
if(a[i]>=48&&a[i]<=57)
{
n=a[i]-48;
}
sum=sum+n*pow(17,j);
j++;
}
printf("\n\nThe
Output is : %d",sum);
return
0;
}
Output:
Thank You ...