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.
[Link] 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;
}