Showing posts with label variable size seven segment display. Show all posts
Showing posts with label variable size seven segment display. Show all posts

Monday 17 December 2012

C CODE TO GENERATE TO VARIABLE SIZE SEVEN SEGMENT DISPLAY

Now guyz ...
Here's a small crap of how to display a 7 seg. o/p by entering any number ....

Well .. Its a bit crappy to write the i/p and o/p here ..
But just try the code :


#define P printf
#define S scanf
#include<stdio.h>
#include<conio.h>
main()
{
 int n[4],m,size=0,i=0,j=0,cnt=1;
 int temp=0,row=0,col=0,p=0;
while(1)
 {
 P("Enter the size preffered :\n");
 S("%d",&size);
 row=2*size+3;
 col=size+2;
 char matrix[4][row][col];
 temp=(row/2)-1;           

 for(i=0;i<row;i++)
 {
  for(j=0;j<col;j++)
  {
   for(p=0;p<=3;p++)
   {
     matrix[p][i][j]='\0';                 
   }                 
  }
}

 i=0;j=0;
 P("Enter the number.\n");
 fflush;
S("%d %d %d %d",&n[0],&n[1],&n[2],&n[3]);
i=0;j=0;

for(p=0;p<=3;p++)
{
                 
switch(n[p]) //Switch 1
 {
   case 2:
   case 3:
   case 5:
   case 6:
   case 7:
   case 8:
   case 9:
   case 0:
        {
          for(j=1;j<=col-2;j++)
          matrix[p][0][j]='_';              
        
        }break;       
 }//Switch_1 ends

  switch(n[p]) //Switch 2
 {
   case 2:
   case 3:
   case 4:
   case 5:
   case 6:
   case 8:
   case 9:
        {
          
          for(j=1;j<=col-2;j++)
          matrix[p][row/2][j]='_';              
        }break;       
}//Switch_2 ends


  switch(n[p]) //Switch 3
 {
   case 0:
   case 2:
   case 3:
   case 5:
   case 6:
   case 8:
        {
          for(j=1;j<=col-2;j++)
          matrix[p][row-1][j]='_';              
        }break;       
 }//Switch_3 ends
  

  switch(n[p]) //Switch 4
 {
   case 4:
   case 5:
   case 6:
   case 8:
   case 9:
   case 0:

        {
          for(j=1;j<=temp;j++)
          matrix[p][j][0]='|';              
        }break;       
 }//Switch_4 ends 

 switch(n[p]) //Switch 5
 {
   case 0:
   case 2:
   case 6:
   case 8:
        {
          for(j=temp+2;j<=row-2;j++)
          matrix[p][j][0]='|';              
        }break;       
      
 }//Switch_5 ends 


  switch(n[p]) //Switch 6
 {
   case 1:
   case 2:
   case 3:
   case 4:
   case 7:
   case 8:
   case 9:
   case 0:
        {
     
          for(i=1;i<=temp;i++)
          matrix[p][i][col-1]='|';              
        }break;       

 }//Switch_6 ends


 switch(n[p]) //Switch 7
 {
   case 0:
   case 1:
   case 3:
   case 4:
   case 5:
   case 6:
   case 7:
   case 8:
   case 9:
        {
          for(j=temp+2;j<=row-2;j++)
          matrix[p][j][col-1]='|';              
        }break;       
 }//Switch_7 ends 

}//Assignment ends


 for(i=0;i<=row-1;i++)
{
 for(p=0;p<=3;p++)   
   { 
    for(j=0;j<=col-1;j++)
    {  
      P("%c",matrix[p][i][j]);                 
    }
  for(cnt=0;cnt<=size/2;cnt++)
  P(" ");
 }
P("\n"); 
}

P("\n\n\n");
}//While 1 ends ....
getch();

}