Easy Tutorial
❮ C Constants C Function Atan2 ❯

C Exercise Example 82

C Language Classic 100 Examples

Title: Octal to Decimal Conversion

Program Analysis: None.

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015 tutorialpro.org. All rights reserved.
//

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n=0,i=0;
    char s[20];
    printf("Please enter an octal number:\n");
    gets(s);
    while(s[i]!='\0'){
        n=n*8+s[i]-'0';
        i++;
    }
    printf("The entered octal number converted to decimal is\n%d\n",n);

    return 0;
}

The above example outputs the following result when run:

Please enter an octal number:
16
The entered octal number converted to decimal is
14

C Language Classic 100 Examples

❮ C Constants C Function Atan2 ❯