An Overview

All the necessary study material for b-tech students.

What we have to offer you.

Codes,Syllabus,Study material,Lab manuals,Assignments and many more . . .

Surfing becomes easy.

You can have any material from our website and post your valuable comments for further improvement.

Get the latest techno news

Get yourself updated with this fast changing dynamic world and all the changes in b-tech pattern.

All the best resources for you.

We have done our level best to provide you with the best of the degree and thus this site is devoted to b-tech exclusively.

Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

31 December 2011

Program in UNIX to generate Fibonacci series

$ cat>fibonacci.sh
echo enter value of n
read n
A = 0
B = 1
I = 3
echo $A
echo $B
C = ‘expr $A + $B’
while [ $i -1e $n ]
do
echo $C
A = $B
B = $C
C = ‘expr $A + $B’
i = ‘expr $i + 1’
done

30 December 2011

A program in UNIX to check if a number a is prime or not

$ cat>prime.sh
echo enter value of n
read n
flag = 0
k = 2
f = ‘expr $n\ /2’
while [ $k –ne $f ]
do
m = ‘expr $n \% $k’
If [ $n –eq 0]
then
flag = 1
echo the number is not prime
break ;
fi
k = ‘expr $k +1’
done
If [ $flag –eq 0]
then
echo the number is prime
fi

26 December 2011

UNIX shell script to find the factorial of given number

$ cat>factorial.sh
echo enter value of n
read n
If [$n –eq 0]
then
echo factorial of given number is 1
fi
If [$n -1t 0]
then
echo factorial of given number is not possible
else
temp = ‘expr $n – 1’
while [ $temp –gt 1]
do
$n = ‘expr $n \* $temp’
temp = ‘expr $temp – 1’
done
echo factorial of given number is $n
fi

17 November 2011

A man walking in rain.

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

void rain(int x1,int y1,int x2,int y2)
{
int s,dx,dy,m,c=0,t=1;
float xi,yi,x,y;

dx=x2-x1;
dy=y2-y1;

if(abs(dx)>abs(dy))
s=abs(dx);
else
s=abs(dy);

xi=dx/(float)s;
yi=dy/(float)s;

x=x1;
y=y1;

putpixel(x1+0.5,y1+0.5,9);

for(m=0;m<s;m++)
{
c++;
x+=xi;
y+=yi;
if(getpixel(x,y)==4)
break;
if(c%10==0)
t++;
putpixel(x+0.5,y+0.5,0);
if(t%2==0)
putpixel(x+0.5,y+0.5,9);

}

}


void main()
{
int gd=DETECT,gm=DETECT,c=-200,i=0,x=40,l=15,h=15,ht=0;
initgraph(&gd,&gm,"");
cleardevice();
setcolor(BROWN);
line(0,201,600,201);

cont:

while(!kbhit())
{
setcolor(4);
ellipse(x,100,0,180,50,30);
line(x-50,100,x+50,100);
line(x,100,x,150);
circle(x-20,115,15);
line(x-20,130,x-20,175);
line(x-20,175,x-20-l,200);
line(x-20,175,x-20+l,200);
line(x-20,140,x,150);
line(x-20,140,x-20-h,160);


for(i=0;i<620;i+=20)
{
rain(i,c,i,200);
}
c++;
if(c==0)
c=-100;
setcolor(0);
delay(50);
ellipse(x,100,0,180,50,30);
line(x-50,100,x+50,100);
line(x,100,x,150);
circle(x-20,115,15);
line(x-20,130,x-20,175);
line(x-20,175,x-20-l,200);
line(x-20,175,x-20+l,200);
line(x-20,140,x,150);
line(x-20,140,x-20-h,160);

line(x+50,100,x+50,200);
x++;
l--;
if(l==-15)
l=15;
if(ht==1)
h++;
else h--;

if(h==15)
ht=0;
else if(h==-15)
ht=1;

}
if(getch()==' ')
{
while(!kbhit());
getch();
goto cont;
}

}

Fill bucket with water programin C

#include<conio.h>
#include<dos.h>
#include<graphics.h>

void main()
{
int gd=DETECT,gm=DETECT,i,j;
initgraph(&gd,&gm,"");
ellipse(300,200,0,360,50,25);
ellipse(300,300,0,360,50,25);
line(250,200,250,300);
line(350,200,350,300);
ellipse(300,100,180,360,5,2);
line(295,100,295,80);
line(305,100,305,86);
arc(300,80,90,180,5);
putpixel(306,85,15);
putpixel(307,84,15);
line(308,84,630,84);
line(300,75,303,75);
line(314,75,630,75);
putpixel(304,74,15);
putpixel(305,73,15);
line(306,72,306,65);
line(311,72,311,65);
putpixel(312,73,15);
putpixel(313,74,15);
pieslice(309,62,0,360,5);
setfillstyle(SOLID_FILL,BLUE);
setcolor(BLUE);
for(i=0;i<7;i++)
{
line(297+i,103,297+i,300);
}
for(i=1;i<100;i++)
{
setcolor(LIGHTBLUE);
ellipse(300,300-i,180,360,4,2);
delay(30);
fillellipse(300,300-i,49,25);
setcolor(1);
line(297,275-i,303,275-i);
setcolor(15);
ellipse(300,200,180,360,50,25);
delay(50);
}
ellipse(300,200,0,360,50,25);
setcolor(0);
for(i=0;i<7;i++)
line(297+i,103,297+i,174);
getch();
}

Moving wheel program in C


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>

int l=1;

void ddaline(int x1,int y1,int x2,int y2)
{

int s,dx,dy,m;
float xi,yi,x,y;

dx=x2-x1;
dy=y2-y1;

if(abs(dx)>abs(dy))
s=abs(dx);
else
s=abs(dy);

xi=dx/(float)s;
yi=dy/(float)s;

x=x1;
y=y1;

putpixel(x1+0.5,y1+0.5,15);

for(m=0;m<s;m++)
{
x+=xi;
y+=yi;
putpixel(x+0.5,y+0.5,15);
}
}


void plotpoints1(int x,int y,int cx,int cy)
{
putpixel(cx+x,cy+y,15);
putpixel(cx-x,cy-y,15);
putpixel(cx-y,cy+x,15);
putpixel(cx+y,cy-x,15);
if(l%20==0)
{
ddaline(cx-x,cy-y,cx+x,cy+y);
ddaline(cx-y,cy+x,cx+y,cy-x);
}
l++;
}

void plotpoints2(int x,int y,int cx,int cy)
{

putpixel(cx-x,cy+y,15);
putpixel(cx+x,cy-y,15);
putpixel(cx+y,cy+x,15);
putpixel(cx-y,cy-x,15);
if(l%20==0)
{
ddaline(cx+x,cy-y,cx-x,cy+y);
ddaline(cx-y,cy-x,cx+y,cy+x);
}
l++;
}


void mcircle(int cx,int cy,int r)
{
int x=0,y,p;

y=r;
p=1-r;


while(x<y)
{
plotpoints1(x,y,cx,cy);
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
}



x=y+1;
while(abs(x)>0)
{
plotpoints2(x,y,cx,cy);
x--;
if(p>=0)
p =p-2*x-1;
else
{
y++;
p=p-2*(x-y)-1;
}
}
}

void main()
{
int gd=DETECT,gm=DETECT;
initgraph(&gd,&gm,"");

int i=0;

while(i<300)
{
cleardevice();
mcircle(100+(i++),200,100);
delay(90);
i++;
}
getch();
}

A program in c for pendulum


#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<process.h>

int cx=300,cy=100,r=300;
int x=0,y,p;

int path(int dtn)
{
int x1,y1;
setcolor(15);
if(x>=y)
{
return 0;
}
cleardevice();

if(dtn==1)
{
circle(cx+x,cy+y,20);
line(cx,cy,cx+x,cy+y);
}
else
{
circle(cx-x,cy+y,20);
line(cx,cy,cx-x,cy+y);
}
delay(10);
if(kbhit())
exit(0);
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
x1=x;
y1=y;
path(dtn);

cleardevice();
if(dtn==1)
{
circle(cx+x1,cy+y1,20);
line(cx,cy,cx+x1,cy+y1);
}
else
{
circle(cx-x1,cy+y1,20);
line(cx,cy,cx-x1,cy+y1);
}
delay(10);
if(kbhit())
exit(0);
}



void main()
{
int gd=DETECT,gm=DETECT;
initgraph(&gd,&gm,"");
cleardevice();
putpixel(300,100,4);
while(1)
{
x=0;
y=r;
p=1-r;
path(1);
x=0;
y=r;
p=1-r;
path(0);
}
getch();
}

Length program using classes.

#include<iostream.h>
#include<conio.h>
class db;
class dm
 {
  float mt;
  int cm;
  public:
  void getdata(void);
  void display(void);
  friend dm add(dm,db);
  };
  class db
  {
  int feet;
  float inches;
  public:
  void getdata(void);
  void display(void);
  friend dm add(dm,db);
  };   void dm :: getdata(void)
  {
  clrscr();
  cout<<"\t\tDM GETDATA FUNCTION\n\n";
  cout<<"Enter Values for metres :-";
  cin>>mt;
  cout<<"Enter Values for centimetres:-";
  cin>>cm;
  }
  void dm :: display(void)
  {
  cout<<"\n\nThe value of distance in metres is"<<mt;
  cout<<"\nThe value of distance in Centimetres is "<<cm;
  }
  void db ::getdata(void)
  {
  clrscr();
  cout<<"\t\tDB GETDATA FUNCTION\n\n";
  cout<<"\n\nEnter Values forn feet:-";
  cin>>feet;
  cout<<"Enter Values for inches:-";
  cin>>inches;
  }
  void db :: display(void)
  {
  cout<<"\n\nThe value of distance in feet is "<<feet;
  cout<<"\nThe value of distance in inches is"<<inches;
  }
  dm add(dm a,db b)
  {
  dm temp;
  temp.cm=a.cm+(b.feet*30)+((b.inches*30)/12.0);
  temp.mt=a.mt+(temp.cm% 100);
  temp.cm=temp.cm-((temp.cm% 100)*100);
  return(temp);
  }
  void main()
  {
  dm a;
  a.getdata();
  db b;
  b.getdata();
  clrscr();
  cout<<"\n\t\tAFTER CONVERSION AND THEIR ADDITION IS PERFORMED\n";
  //extra variable of type dm to display result of adding two different types of distance
  dm extra;
  extra=add(a,b);
  extra.display();
  getch();
  }

 

A class program to display ages of father,daughter and son.

#include<iostream.h>
#include<conio.h>
class father
{
  protected:
   int age;
  public:
   father(int x)
   {
     age=x;
   }
   virtual void iam()
   {
     cout<<"I AM THE FATHER, my age is "<<age;
   }
};
class son:public father
{
  public:
   son(int s):father(s)
   {
     age=s;
   }
   void iam()
   {
     cout<<"I am son, my age is "<<age;
   }
};
class daughter:public father
{
  public:
   daughter(int d):father(d)
   {
     age=d;
   }
   void iam()
   {
     cout<<"I am daughter, my age is "<<age;
   }
};
void main()
{
  father f1(45),*ptr;
  son s1(20);
  daughter d1(18);
  clrscr();
  cout<<"ptr point the base class father obj\n";
   ptr=&f1;
   ptr->iam();
  cout<<"\n\nptr point the class son obj\n";
   ptr=&s1;
   ptr->iam();
  cout<<"\n\nptr point the class daughter obj\n";
   ptr=&d1;
   ptr->iam();
  getch();
}

15 November 2011

Insert the node in the begining of the list.

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
 int info;
 struct node* link;
} ;
struct node* obj;
void main()
{  void create();
void insertbeg();
void traverse();
clrscr();
create();
insertbeg();
traverse();
getch();
 }
void create()
{
 struct node*ptr,*nxt;
 char ch;
 ptr=(struct node*)malloc(sizeof(struct node));
 printf("Insert node");
 scanf("%d",&ptr->info);
 obj=ptr;
 do{
 nxt=(struct node*)malloc(sizeof(struct node));
 printf("Insert node");
 scanf("%d",&nxt->info);
 ptr->link=nxt;
 ptr=nxt;
 printf("Enter Y/N to insert more elements");
 ch=getche();
 }
 while(ch=='Y');
 ptr->link=0;
}
void insertbeg()
{       struct node*nxt;
 char c;
       // ptr=(struct node*)malloc(sizeof(struct node));
 nxt=(struct node*)malloc(sizeof(struct node));
 do{
 printf( "Do u want to insert node in the begning of the list");
 c=getche();
 }
 while(c=='Y');
 printf("insert node");
 scanf("%d",&nxt->info);
 nxt->link=obj;
       obj=nxt;
 }
void traverse()
{     struct node*ptrr;
       ptrr=obj;
      do
      {
      printf("%d",ptrr->info);
      ptrr=ptrr->link;
      } while(ptrr!=0);
  }

A DSA program using student as an object.


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct student
{
int tot;
int rollno;
char name[10];
int marks;
struct student *next,*pre;
};
void main()
{
 int sub1,sub2,sub3,sub4,sub5;
 int tot;
 struct student *start,*ptr;
 char ch='y';
 start=NULL;
 clrscr();
 while(ch=='y')
 {
    if(start==NULL)
    {
start=ptr=malloc (sizeof (struct student));
start->pre=ptr;
    }
    else
    {
    ptr->next=malloc (sizeof (struct student));
    ptr->next->pre=ptr;
    ptr=ptr->next;
    }
    ptr->next=NULL;
    printf("\n enter any rollno :");
    scanf("%d",& ptr->rollno);
    printf("\n enter name :");
    scanf("%s",& ptr->name);
    printf("\n enter marks of 1st subject :");
    scanf("%d",& sub1);
    printf("\n enter marks of 2nd subject :");
    scanf("%d",& sub2);
    printf("\n enter marks of 3rd subject :");
    scanf("%d",& sub3);
    printf("\n enter marks of 4th subject :");
    scanf("%d",& sub4);
    printf("\n enter marks of 5th subject :");
    scanf("%d",& sub5);
    ptr->tot=sub1+sub2+sub3+sub4+sub5;
    printf("\n Total marks of a student is  : %d",ptr->tot);
    printf("\n \n enter your choice (y/n):");
    fflush(stdin);
    scanf("%c",& ch);
 }
for(ptr=start;ptr!=NULL;ptr=ptr->next)
{
printf("\n\n Rollno. of a student : %d",ptr->rollno);
printf("\n Name of a student : %s",ptr->name);
printf("\n Total marks of a student : %d",ptr->tot);
}
getch();
}

a program in DSA as employee que


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct employee
{
int emp_id;
char emp_name[15];
int bs;
float gs;
struct employee *next;
};
struct queue
{
struct employee *rear;
struct employee *front;
};
void main()
{
int bs;
float ta,da,hra,gs;
struct employee *emp1;
struct queue *queue1;
char ch='y';
clrscr();
queue1=NULL;
while(ch=='y')
{
emp1= malloc(sizeof (struct employee));
if (queue1==NULL)
{
queue1->front=queue1->rear=emp1;
}
else
{
queue1->front=emp1;
queue1->front=queue1->front->next;
}
queue1->front->next=NULL;
printf("\n Enter employee id : ");
scanf("%d",& emp1->emp_id);
printf("\n Enter employee name :");
scanf("%s",& emp1->emp_name);
printf("\n Enter basic salary :");
scanf("%d",& emp1->bs);
ta=0.20*bs;
da=0.40*bs;
hra=0.15*bs;
gs=bs+ta+da+hra;
printf("\n\t Gross salary of employee is : %f",gs);
printf("\n\n\t Enter your choice(y/n) :");
fflush(stdin);
scanf("%c",& ch);
}
for(  ;queue1->front!=NULL;queue1->front=queue1->front->next)
{
printf("\n emp_id = %d",emp1->emp_id);
printf("\n emp_name = %s",emp1->emp_name);
printf("\n basic salary = %d",emp1->bs);
printf("\n gross salary = %f\n",gs);
}
if(gs>15000)
{
printf("\n\tGross salary is more than 15000");
}
else
{
printf("\n\tGross salary is less than 15000");
}
getch();
}

A DSA program showing que.


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node*next;
};
struct queue
{
struct node*rear;
struct node *front;
};
void main()
{
struct node *node1;
struct queue *queue1;
char ch='y';
queue1=NULL;
while(ch=='y')
{
node1=malloc(sizeof(struct node));
if(queue1==NULL)
{
queue1->front=queue1->rear=node1;
}
else
{
queue1->front=node1;
queue1->front=queue1->front->next;
}
queue1->front->next=NULL;
printf("\n enter any value ") ;
scanf("%d",&node1->info) ;
printf("\n do you want to more press your choice(Y/N) :") ;
fflush(stdin);
scanf("%c",&ch);
}
for( ;queue1->front!=NULL;queue1->front=queue1->front->next)
{
printf("%d",queue1->front->info);
}
getch();
}