Advertisement

Sunday, 16 September 2018

5 Bit Binary Up-Down Counter Program in C++




5 bit binary up and down counter counts from 0 to 31 (Up counter) or 31 to 0 (down counter) in binary form.



C++ Program for 5 Bit Binary Up-Down Counter (Turbo C++)


#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
          clrscr();
          int a[4];
          int c;
          cout<<"\n Enter the choice - 1) for up & 0) for Down \n";
          cin>>c;
         
          if(c==1 || c==0)
          {
              cout<<"\n COUNTER \n";
             
              for(int m=0;m<=4;m++)
                {
                a[m]=0;
                }
              for(int i=0;i<5 i="" span="">
              cout<
              cout<<"\t";
             
              for(i=0;i<31 i="" span="">
              {
                     for(int j=4;j>=0;--j)
                       {
                           a[j]=1-a[j];
                           if(a[j]==c)
                           break;
                        }
                     for(int k=0;k<=4;k++)
                      {
                      cout<
                      }
                      cout<<"\t";
                  
              }
          }
         
          else
          {
              cout<<"\n WRONG CHOICE";
          }
            getch();
}




No comments:

Post a Comment