This document describes a C programming exercise to convert decimal numbers to binary. It provides the source code for a program that uses printf, scanf, while and for loops, and if/else conditions to take a decimal number as input from the user, perform binary conversions by taking the remainder of successive divisions by 2, and store the results in reverse order in an array before printing out the final binary number. It explains that storing in reverse order and then directly printing is done to output the binary number with the least significant bit first instead of last.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views
Laboratory Course Programming: Description
This document describes a C programming exercise to convert decimal numbers to binary. It provides the source code for a program that uses printf, scanf, while and for loops, and if/else conditions to take a decimal number as input from the user, perform binary conversions by taking the remainder of successive divisions by 2, and store the results in reverse order in an array before printing out the final binary number. It explains that storing in reverse order and then directly printing is done to output the binary number with the least significant bit first instead of last.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
Laboratory Course Programming
Exercise 3 :convert decimal in to binary
Students: 1. Pruthvi Jivanbhai Davara I.D. No-25758 Study prog:E.T . 2. Chirag Nareshbhai Vekariya I.D. No-25736 Study prog:E.T. 3.Jay Vinodkumar Ginoya I.D. No-25808 Study prog:E.T Description: This is the c programming to convert decimal in to binary. This program contains printf,scanf commands . while and for loops and if else condition. When program is being run user has to input inputnumber. Then the condition of while loop is checked and if condition is true then formula which given in while loop runs and answer of formula comes in to for loop as input then again condition is checked and if condition is again true then it gives output to user by using printf command .
During this process we take the remainder of the inputnur/2 but we want reverse positions of our remainder last remainder has to be at first position and first has to be at last so here we have done one thig that during whole process we gave command on array to store this values in reverse and then with second loop we just printf our output directly .
Source code: #include<stdio.h> int main(void) { int inputnumber; int a=0; int j; int binarynumber[16]; printf("please enter your decimal value :"); scanf("%d",&inputnumber); if(inputnumber<65536) { while(a<=15) { binarynumber[15-a]=inputnumber%2; inputnumber=inputnumber/2; a++; } for(j=0; j<=15; j++) { printf("%2d",binarynumber[j]); } } else {printf("your inputnumber is out of range.........sorry!!!!\n"); } printf("\n"); return 0; }