Solved programming problem

Convert Decimal Number To any Base in C.

Source code

#include <stdio.h>

int main()

{

    int n,convert;

    int result=0,pos=1;

    printf("Please Enter the Decimal Number: ");

    scanf("%d",&n);

    printf("Please Enter The Base Number Which You Want to Convert: ");

    scanf("%d",&convert);

    while(n!=0)

    {

        result=result+(n%convert)*pos;

        pos=pos*10;

        n=n/convert;

    }

    printf("
Converted Value: %d
",result);

   

    return 0;

}

Output

Please Enter the Decimal Number:120

Please Enter The Base Number Which You Want to Convert:8

Converted Value:170

Join the discussion

Add your comment