๐Ÿ’ป
B.TECH I YEAR โ€ข I SEMESTER โ€ข R25

Programming for Problem Solving - Lab Manual

C Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š I Semester ๐Ÿ’ป C Programming ๐Ÿงช Lab Program
Selected Program

Write a program that shows the binary equivalent of a given positive number between 0 to 255

โ† All Lab Programs

Write a program that shows the binary equivalent of a given positive number between 0 to 255

Algorithm

start
	step1: Read number
	step2: if (number < 0 OR number > 255) then
	step3: 	Print "Number is out of range." stop
	step4: for i:=7 to 0 step -1 do
	step5:  bit := (number >> i) AND 1
	step6: 	print bit
stop

Flowchart
flowchart for binary equivalent of a given positive number in c

C Programming
//Binary equivalent of a given positive number between 0 to 255.
#include <stdio.h>

int main() {
    static int number,bit,i;

    // Prompt the user for input
    printf("Enter a number: ");
    scanf("%d", &number);

    // Validate the input
    if (number < 0 || number > 255) {
        printf("Number is out of range.\n");
        return 1; // Exit with error code
    }

    for (i = 7; i >= 0; i--)
    {
        bit = (number >> i) & 1;
        printf("%d", bit);
    }
    return 0; // Successful execution
}

OUTPUT
Enter a number: 56
00111000

๐Ÿ’ป Run This C Program

Write a program that shows the binary equivalent of a given positive number between 0 to 255
The selected C program is loaded automatically. Edit the code, provide input through STDIN and click Run.

The compiler is embedded using OneCompiler. Your program runs in the embedded C environment; Study Glance does not execute C code directly on your web server.
โ† Back to PPS Lab Programs ๐Ÿ“š All Lab Manuals