Commit b6d171c3 by viakul

Update 4thtask.c

parent f895dd08
Showing with 3 additions and 38 deletions
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int isInt(char* x,int y);
int moreInt(char* x,int y, int i);
int DeciConv(char x, int y) ;
int main()
{
......@@ -24,7 +22,7 @@ int main()
printf("Decimal equivalent of %s in base %d is %d\n", x, y, DeciConv(x, y));
puts("this is the right input");
printf("%s",line);
return 0;
}
......@@ -83,38 +81,4 @@ int isInt(char* x,int y){
}
return(bool);
}
int DeciConv(char x, int y)
{
int len = strlen(x);
int power = 1;
int num = 0;
int i;
for (i = len - 1; i >= 0; i--)
{
if (val(x[i]) >= y)
{
printf("Invalid Number");
return -1;
}
num += val(x[i]) * power;
power = power * base;
}
return num;
}
int val(char c)
{
if (c >= '0' && c <= '9'){
return (int)c - '0';
}
else{
return (int)c - 'A' + 10;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment