Ad

Chapter - 4: The Loop Control Structure

Write a program to find the octal equivalent of the entered number. Hint: To obtain octal equivalent fo an integer, divide it continuously by 8 till dividend doesn't become zero, then write the remainders obtained in reverse direction.


Ad
B
Sections
8
Exercises
#include<stdio.h>
#include<conio.h>
int main()
{
	
	int num, ans = 0, temp, i;
	printf("Enter a number : ");
	scanf("%d", &num);
	
	for(i = 1; num; i *= 10)
	{
		temp = num % 8;
		ans += temp*i;
		num /= 8;
	}
	
	//To check, octal eq. of 15 is 17.
	
	printf("\n\n%d is the octal equivalent of %d.", ans, num);
	getch();
	return 0;
}
Ad

© 2024 Garbage Valuegarbage value logo