Write a program in C++ to convert a octal number to decimal number

  • برمجة سي بلس بلس
  • برمجة

Write a program in C++ to convert a octal number to decimal number

Sample Output:

 Convert any octal number to decimal number:                           
----------------------------------------------------                   
 Input any octal number: 17                                            
 The equivalent decimal number: 15

الأجوبة

#include <iostream>
#include <math.h>
using namespace std;
 
int main()
{
    long octal_num, decimal_num = 0;
     int i = 0;
	cout << "\n\n Convert any octal number to decimal number:\n";
	cout << "----------------------------------------------------\n";
	cout << " Input any octal number: ";
	cin>> octal_num;
    while (octal_num != 0) 
     {
      decimal_num = (long)(decimal_num + (octal_num % 10) * pow(8, 

i++));
      octal_num = octal_num / 10;
     }
    cout<<" The equivalent decimal number: " << decimal_num << "\n";	
} 
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...