Wednesday, 16 April 2014

// // Leave a Comment

Program for Register Requirement


Program for calculate Register Requirement for the given postfix notation

#include<stdio.h>
#include<conio.h>
#include<string.h>

struct rr
{
    char nm;
    int rr;
}r[200];

struct quard
{
    char op1,op2,op,r;
}q[5];
int j,k;
int search(char tmp)
{     int l=0;
    for(l=0;l<k;l++)
      {
         if(tmp==r[l].nm)
        return(r[l].rr);
      }
      return(-1);
 }

void main()
{
    char a[30],c='1';
    int i,len,LR,RR1;
    clrscr();
    printf("enter expression in postfix notation:\n ");
    scanf("%s",a);
    i=0;
    j=0;
    len=strlen(a);
    while(len!=1)
    {       i=0;
        while(a[i]!='\0')
        {
            if((a[i]=='+')||(a[i]=='-')||(a[i]=='*')||(a[i]=='/'))
            {    q[j].op1=a[i-2];
                q[j].op2=a[i-1];
                q[j].op=a[i];
                q[j].r=c;
                a[i-2]=c;
                c++;
                j++;
                for(;a[i+1]!='\0';i++)
                {
                   a[i-1]=a[i+1];
                }
                break;
            }  //if
              else
             i++;
        } //inner while
             len=len-2;
    }       //outer while
    printf("quard table is:\n\n");
    printf("op1\top2\top\tr\n");
    for(i=0;i<j;i++)
    {
        printf("%c\t%c\t%c\t%c\n",q[i].op1,q[i].op2,q[i].op,q[i].r);
    }

    //register requirement
    k=0;
    for(i=0;i<j;i++)
    {    if(i==0)
        {
            r[k].nm=q[i].op1;
            r[k].rr=1;
            k++;
            r[k].nm=q[i].op2;
            r[k].rr=0;
            k++;
            r[k].nm=q[i].op;
            r[k].rr=1;
            k++;
            r[k].nm=q[i].r;
            r[k].rr=r[k-1].rr;
            k++;
        }
       else
        {
            LR=search(q[i].op1);
            if(LR==-1)
             {
              r[k].nm=q[i].op1;
              r[k].rr=1;
              k++;
              LR=1;
             }
            RR1=search(q[i].op2);
            if(RR1==-1)
             {
              r[k].nm=q[i].op2;
              r[k].rr=0;
              k++;
              RR1=0;
             }
               r[k].nm=q[i].op;
             if(LR!=RR1)
                r[k].rr=(LR>RR1)?LR:RR1;
             else
                r[k].rr=LR+1;
             k++;
             r[k].nm=q[i].r;
             r[k].rr=r[k-1].rr;
             k++;
        }
       }
       printf("\nregister requirement table:\n");
       for(i=0;i<k;i++)
       {
        printf("%c\t%d\n",r[i].nm,r[i].rr);
       }

    getch();
}

Output:
(It is necessary to enter the expression in POSTFIX notation)




Read More

Tuesday, 11 February 2014

// // Leave a Comment

Program for changing background color

Here is a program to change the color of the background.In this the choices will be taken from the user and display the respective output.
In this program for making choice i use the switch case.



#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
int main(void)
{
    int  i,Graphdriver = DETECT,Graphmode, Errorcode,n;        
    initgraph( &Graphdriver, &Graphmode, "C:\\TURBOC3\\BGI" );

    Errorcode = graphresult();
    if( Errorcode != grOk )
    {
        printf(" Graphics System Error: %s\n", grapherrormsg( Errorcode ) );
        exit( 1 );
    }

    cleardevice();
    
for(i=0;i<13;i++)
      {
    cleardevice();
    printf("which color is set as background color:\n");
    printf("1.Blue\t\t2.Red\t\t3.Graan\t\t4.Cyan\t\t5.Brown\t\t\n6.LightGray\t7.DarkGray\t");
    printf("8.LightGreen\t9.LightBlue\t10.LightCyan\t\n11.LightRed\t12.LightMagenta\t13.Yellow");
    printf("\t14.Magenta\t15.exit\n");
    printf("\nenter choice:-");
    scanf("%d",&n);
    switch(n)
    {
        case 1:setbkcolor(BLUE);
            break;
        case 2:setbkcolor(RED);
            break;
        case 3:setbkcolor(GREEN);
            break;
        case 4:setbkcolor(CYAN);
            break;
        case 5:setbkcolor(BROWN);
            break;
        case 6:setbkcolor(LIGHTGRAY);
            break;
        case 7:setbkcolor(DARKGRAY);
            break;
        case 8:setbkcolor(LIGHTGREEN);
            break;
        case 9:setbkcolor(LIGHTBLUE);
            break;
        case 10:setbkcolor(LIGHTCYAN);
            break;
        case 11:setbkcolor(LIGHTRED);
            break;
        case 12:setbkcolor(LIGHTMAGENTA);
            break;
        case 13:setbkcolor(YELLOW);
            break;
        case 14:setbkcolor(MAGENTA);
            break;
        case 15:printf("exit....");
            exit(0);
            break;
        default:printf("invalid choice......");
            break;
    }

      }
    cleardevice();
    getch();
    return 1;
}

O/P DEMO:-

STEP_1


STEP_2



Read More

Thursday, 23 January 2014

// // Leave a Comment

Programe of CG for moving object

Computer Graphics is very interesting subject.Computer Graphics is one of the subject in Engineering.The term"Computer Graphics"is a combination of two things:that is Graphic and Computer. Means that we can create the graphics using the programming language.

Here the simple "C" program of moving one object.
That object is moving Diagonally.

CG PROGRAMME FOR MOVING OBJECT:

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

int main(void)
{

int gdriver = DETECT, gmode, errorcode;
int midx, midy,a=25,b=30,c=70,d=50,e=70;
int radius = 50,i;


initgraph(&gdriver, &gmode,"C:\\TURBOC3\\BGI"); 

/*here in last argument is your"BGI" directory path*/


errorcode = graphresult();
if (errorcode != grOk)  /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

midx = 50;
midy = 50;
setcolor(YELLOW); //Use any colors which are availables in library

for(i=1;i<350;i++)
{

circle(midx,midy, radius); //draw a circle
circle(midx,midy,5);
putpixel(a,b,YELLOW);     //display the pixels
putpixel(c,b,YELLOW);
arc(d,e,180,360,20);     //draw an arc
midx=midx+1;
midy=midy+1;
a=a+1;
b=b+1;
c=c+1;
d=d+1;
e=e+1;                 //suspend the execution
delay(10);
cleardevice();

}

/* clean up */
closegraph();
return 0;
}


SUJJESTION:-
Your program is only run if and only if you save your program in your "BGI" directory
Read More