Commit b6d171c3 by viakul

Update 4thtask.c

parent f895dd08
Showing with 2 additions and 37 deletions
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
int isInt(char* x,int y); int isInt(char* x,int y);
int moreInt(char* x,int y, int i); int moreInt(char* x,int y, int i);
int DeciConv(char x, int y) ;
int main() int main()
{ {
...@@ -24,7 +22,7 @@ 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); printf("%s",line);
return 0; return 0;
} }
...@@ -84,37 +82,3 @@ int isInt(char* x,int y){ ...@@ -84,37 +82,3 @@ int isInt(char* x,int y){
return(bool); return(bool);
} }
\ No newline at end of file
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;
}
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