C Program convert decimal to octal Number

 In this example,we will discuss about how to convert decimal to octal in the c programming language.Following is the solution of the problem.

code:

#include <stdio.h>

#include <math.h>

using namespace std;


int main()


{


   int deciNumber,originalnumber;


    printf("Enter a decimal number: ");

    scanf("%d", &deciNumber);



  originalnumber=deciNumber;


    int octalnumber = 0, i = 1, remainder;

    while (deciNumber != 0) 

    {

           remainder = deciNumber % 8;

        deciNumber /= 8;

        octalnumber += remainder * i;

        i *= 10;

    }


     printf("%d in decimal = %d in octal", originalnumber, octalnumber);


   return 0;

}

Output:

Enter a decimal number: 60

60 in decimal = 74 in octal

Comments

Popular posts from this blog

Diferrence between flutter and react native

Flutter Widgets

Flutter layout