Flowchart to convert Octal to decimal number using while loop in C++
C++ Program to convert Octal to decimal number using while loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> #include <math.h> using namespace std; int main() { int num, temp, rem, oct = 0, i = 0; cout << "Enter an octal number : "; cin >> num; temp = num; while(temp != 0) { rem = temp % 10; oct += rem * pow(8, i++); temp = temp / 10; } cout << "\nDecimal equivalent of " << num << " is : " << oct; return 0; } |
VARIABLE | DECLARATION (LINE NO) | INITILIZATION (LINE NO) | USE (LINE NO) |
NUM | 6 | 12,8 | 16, |
TEMP | 6,10 | 14,9 | 12,14 |
REM | 6 | 12 | 13, |
OCT | 6 | 6,13 | 16 |
i | 6 | 6,13 | 13 |