hi, we have this assignment in our computer subject in school. we need to create a c program that converts decimals to base(2-9) and vice versa. i know how the coversion works but i cant perfect my program. here's my program... i know the output for the 1st case is wrong because it ends up showing in reverse and the last case wont work.
#include <stdio.h>
int main()
{
int n,r,b,sum; char c;
clrscr();;
printf("Enter base type:\nA-base 10 \nB-base R (2-9)");
scanf("%c",&c);
switch(c)
{
case 'A':
case 'a':
{printf("to what base (2-9)");
scanf("%d",&b);
printf("enter number:");
scanf("%d",&n);
for(sum=0;n>0; )
{
r=n%b;
printf("%d", r);
n/=b;}
break;
}
case'B':
case'b':
{printf("Enter base of number");
scanf("%d",&b);
printf("\nenter number:");
for(scanf("%d",&n),sum=0;n>0; )
{
r=n%10;
sum=sum+r;
n=(n/b);
n=(n*b);
}
printf("converted number=%d", sum);
}
}
return 0;
}
hope someone can help me.