Write a C program to convert decimal to octal number.
int main() {
int data, res = 0, i = 1, mod;
/* get the input from the user */
printf("Enter your input:");
scanf("%d", &data);
/* convert decimal to octal */
while (data > 0) {
mod = data % 8;
res = res + (i * mod);
data = data / 8;
i = i * 10;
}
/* print the resultant octal value */
printf("Octal Value: %d\n", res);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input:1089
Octal Value: 2101
Enter your input:1089
Octal Value: 2101
No comments:
Post a Comment