Computer Science, asked by jeyasuryakj, 5 months ago

Write an interactive C program to read an integer. If it is positive, then display the corresponding binary representation of that number. In case the user enters a negative number, then ignore that input and ask the user to re-enter any different number. The user must enter 999 to stop.​

Answers

Answered by kumarguptaa728
0

Explanation:

999" (and any subsequent words) was ignored because we limit queries to 32 words.

Answered by SaurabhJacob
1

#include<iostream>

using namespace std;

void conv(int a){

   int temp[20];

   int in=0;

   while(a!=0){

       temp[in]=a%2;

       a/=2;

       in++;

   }

   cout<<"Binary Equivalent is \"";

   for(in=in-1;in>=0;in--){

       cout<<temp[in];

   }

   cout<<"\"";

}

int main(){

   int num;

   do{

       cout<<"menu _exit_condition";

       cout<<"\n\t\tEnter the number = ";

       cin>>num;

       if(num>0)

           conv(num);

   }while(num!=999);

}

  • To display the binary equivalent, a conv() function is created.
  • Where a temporary array is used to store the remainder by dividing the number by 2 and storing it in reverse order.
  • In the main function, we have used the do-while() loop to show the menu to the user.
  • Here while is having a condition to execute the do statement till the number entered by the user is 999.
Similar questions