Answer to Question #305435 in Algorithms for Mohit

Question #305435

write an algorithm,draw a flow chart and write its corresponding c program to convert a decimal number to its equivalent binary number



1
Expert's answer
2022-03-04T04:04:31-0500




#include <stdio.h>
#include <stdlib.h>


int main(){
	int decimal, index, result=0,i;
	int binary[100];
	printf("Enter number: ");
	scanf("%d",&decimal);
	index = 0;
	while(decimal > 0){
		binary[index] = decimal % 2;
		index=index+1;
		decimal = decimal/2;
	}
	for(i = index-1; i>= 0;i--){
		printf("%d",binary[i]);


	}
	printf("\n\n");
	getchar();
	getchar();
	return 0;
}


algorithm


Start
    Declare variables decimal, index, result
    Declare array binary[] 
    Read decimal
    Set index = 0
    while decimal > 0 do
       binary[index] = decimal mod 2
       index=index+1
       decimal = decimal/2
    end while
    for i = index-1 to 0 Step -1
       Set result=result+binary[i]
    End for
    Display result  
Stop



flow chart 


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS