خرید بک لینک

gameover.blog.ir



/* C++ programming source code to convert either octal to decimal or decimal to octal according to data entered by user. */

#include <iostream>
#include <cmath>
using namespace std;
int decimal_octal(int n);
int octal_decimal(int n);
int main()
{
   int n;
   char c;
   cout << "Instructions: " << endl;
   cout << "1. Enter alphabet 'o' to convert decimal to octal." << endl;
   cout << "2. Enter alphabet 'd' to convert octal to decimal." << endl;
   cin >> c;
   if (c =='d' || c == 'D')
   {
       cout << "Enter a octal number: ";
       cin >> n;
       cout << n << " in octal = " << octal_decimal(n) << " in decimal";
   }
   if (c =='o' || c == 'O')
   {
       cout << "Enter a decimal number: ";
       cin >> n;
       cout << n << " in decimal = " << decimal_octal(n) << " in octal";
   }
   retu 0;
}

int decimal_octal(int n) /* Function to convert decimal to octal */
{
    int rem, i=1, octal=0;
    while (n!=0)
    {
        rem=n%8;
        n/=8;
        octal+=rem*i;
        i*=10;
    }
    retu octal;
}

int octal_decimal(int n) /* Function to convert octal to decimal */
{
    int decimal=0, i=0, rem;
    while (n!=0)
    {
        rem = n%10;
        n/=10;
        decimal += rem*pow(8,i);
        ++i;
    }
    retu decimal;
}

Output

Instructions:
1. Enter alphabet 'o' to convert decimal to octal.
2.  Enter alphabet 'd' to convert octal to decimal.
d
Enter an octal number: 2341
2341 in octal = 1249 in decimal

برچسب: برنامه تبدیل عدد به حروف در اکسل,برنامه تبدیل عدد به حروف,برنامه تبدیل عدد به بارکد,برنامه تبدیل عدد به حروف c,برنامه تبدیل عدد به حروف در ,c,برنامه تبدیل عدد به مبنای 2,برنامه تبدیل عدد دهدهی به دودویی,برنامه تبدیل عدد به باینری,برنامه تبدیل عدد به حروف در اکسس,برنامه تبدیل عدد باینری به دهدهی, نویسنده: ایلیا حیدری تاريخ: شنبه 17 مهر 1395 ساعت: 2:15

صفحه بندی