google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: April 2015

Tuesday, April 28, 2015

To solve multiplication of numbers in few seconds

Example 1
Calculate 98 * 93
Solution
Select a closest base ( a power of 10). In this case we can select 100 as a base. Write these numbers with the difference from the base. That is 98-100 = -2 and 93-100 is -7. So write it as
98   :   -2
93   :   -7
Left side of the answer will be the diagonal sum including their signs. That is 98-7=91. So 91 will be the left side of the product. (You can take the other diagonal sum also, that is 93-2=91. Always these diagonal sums will be same).
To find the right hand side, just multiply the differences including their signs. That is -2 * -7 = 14
So we got that left side of the product is 91 and right side is 14. So answer is 9114



Example 2
Calculate 96 * 112
Solution
Use the same method. Let's select 100 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 96-100 = -4 and 112-100 is 12. So write it as
96    :   -4
112  :   12
Take the diagonal sum to get the left side of the product. That is 96+12 = 108 (Or 112-4 = 108).
For the right side, find the product of the differences. That is -4*12 = -48. Since it is -ve, we need to make it as +ve. For this borrow 1 from our left hand side 108. This borrowed 1 becomes 100 and our right hand side becomes 100+(-48) = 52. This is our right hand side
Since we borrowed one from left hand side, left hand side is 107
So answer is 10752



Example 3
Calculate 103 * 115
Solution
Use the same method. Let's select 100 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 103-100 = 3 and 115-100 is 15. So write it as
103  :   3
115  :   15
Take the diagonal sum to get the left side of the product. That is 103+15 = 118 (Or 115+3= 118).
For the right side , find the product of the differences. That is 3*15 = 45.
So answer is 11845



Example 4
Calculate 122 * 89
Solution
Use the same method. Let's select 100 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 122-100 = 22 and 89-100 is -11. So write it as
122  :  22
89    :   -11
Take the diagonal sum to get the left side of the product. That is 122+(-11) = 111 (Or 89+22= 111).
For the right side , find the product of the differences. That is 22*(-11) = -242. Since it is -ve, we need to make it as +ve. For this borrow 3 from our left hand side 111. This borrowed 3 becomes 300 and our right hand side becomes 300+(-242) = 58. This is our right hand side
Since we borrowed 3 from left hand side, left hand side is 108
So answer is 10858



Example 5
Calculate 1024 * 989
Use the same method. Let's select 1000 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 1024-1000 = 24 and 989-1000 is -11. So write it as
1024  :  24
989    :  -11
Take the diagonal sum to get the left side of the product. That is 1024+(-11) = 1013 (Or 989+24= 1013).
For the right side, find the product of the differences. That is 24*(-11) = -264. Since it is -ve, we need to make it as +ve. For this borrow 1 from our left hand side 1013. This borrowed 1 becomes 1000 and our right hand side becomes 1000+(-264) = 736.
Since we borrowed 1 from left hand side, left hand side is 1012 now.
So our answer is 1012736



Example 6
Calculate 997 * 986
Use the same method. Let's select 1000 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 997-1000 = -3 and 986-1000 is -14. So write it as
997  : -3
986  :  -14
Take the diagonal sum to get the left side of the product. That is 997+(-14) = 983 (Or 986-3= 983).
For the right side, find the product of the differences. That is (-3)*(-14) = 42. But here 42 has only 2 digits whereas our base 1000 has three zeros. So write 42 as 042.
So our answer is 98304


Monday, April 20, 2015

Quotes and thoughts for peace of mind and to think positive.


“The love of learning, the sequestered nooks, and all the sweet serenity of books” ― Henry Wadsworth Longfellow



“Life is a series of natural and spontaneous changes. Don't resist them; that only creates sorrow. Let reality be reality. Let things flow naturally forward in whatever way they like.” ― Lao Tzu



“There are two ways to get enough. One is to continue to accumulate more and more. The other is to desire less.” ― G.K. Chesterton



“Nothing is so aggravating as calmness.” ― Mahatma Gandhi



“The mind is everything. What you think you become.” – Buddha



“Gratitude is not only the greatest of virtues, but the parent of all others” – Cicero



“For beautiful eyes, look for the good in others; for beautiful lips, speak only words of kindness; and for poise, walk with the knowledge that you are never alone” –Audrey Hepburn



“Forgiveness liberates the soul, it removes fear. That’s why it is such a powerful weapon.” – Nelson Mandela



“Happiness is a state of mind. It’s just according to the way you look at things” – Walt Disney



“The body is the temple of the soul” – Dr. Oz



“You’re even more amazing than you wish you were” – Colin Wright



“When the solution is simple, God is answering” – Albert Einstein



“You yourself, as much as anybody in the entire universe, deserve your love and affection” – Gautama Buddha



“Acceptance is not love. You love a person because he or she has lovable traits, but you accept everybody just because they’re alive and human.” – Albert Ellis



“I bless you with pure love and light. I bless you with purified source energy” – Christie Marie Sheldon



“If you want to be interesting, be interested” – David Ogilvy



“People always ask me: ‘Were you funny as a child?’ Well, no, I was an accountant.” – Ellen DeGeneres



“Hope is being able to see that there is light despite all of the darkness” – Desmond Tutu



“When you say yes, the universe helps you” – Dan Brule



“My philosophy is simple, it is kindness” – Dalai Lama IVX




Share it to make the day of others with feeling of happiness.

Tuesday, April 7, 2015

C program for parenthesized expression using stack

/*PARENTHESIZED EXPRESSION USING STACK */

#include<stdio.h>
#include<conio.h>
#define MAX 10
int top=-1;
int stack[MAX];
void push(char);
char pop();
void main()
{
   char exp[MAX],ch;
   int i,flag=1;
   clrscr();
   printf("\n Enter Infix Expression:-\n");
   gets(exp);
   i=0;
   while(exp[i]!='\0')
   {
     if(exp[i]=='('||exp[i]=='{'||exp[i]=='[')
     {
push(exp[i]);
     }
     if(exp[i]==')'||exp[i]=='}'||exp[i]==']')
     {
       ch=pop();
       if(exp[i]==')'&&(ch=='{'||ch=='['))
       {
flag=0;
       }
       if(exp[i]=='}'&&(ch=='('||ch=='['))
       {
flag=0;
       }
       if(exp[i]==']'&&(ch=='('||ch=='{'))
       {
flag=0;
       }
     }
     i++;
   }
   if(top>=0)
   {
     flag=0;
   }
   if(flag==1)
   {
     printf("\n Valid Expression");
   }
   else
   {
     printf("\n Invalid Expression");
   }
   getch();
}
void push(char c)
{
  if(top==MAX-1)
  {
   printf("\n stack is full");
  }
  else
  {
    top++;
    stack[top]=c;
  }
}
char pop()
{
  char c;
  if(top==-1)
  {
   printf("\n Stack is empty");
  }
  else
  {
   c=stack[top];
   top--;
   return c;
  }
}

C program in stack to concatenate two strings using push and pop functions

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define max 30
void push(char ch);
char pop();
char stack[max];
int top=-1;
void main()
{
char a[20],b[20],k[40],ch;
int i,l1,l2;
clrscr();
printf("\n Enter First String:-\n");
scanf("%s",a);
printf("\n Enter Second String:-\n");
scanf("%s",b);
l1=strlen(a);
l2=strlen(b);
for(i=0;i<l2;i++)
{
 push(b[i]); //push second string into stack
}
push(' ');
for(i=0;i<l1;i++)
{
 push(a[i]); //push first string into stack
}
printf("\n After concatenation of two string:-\n");
i=0;
while(top!=-1)
{
 ch=pop();
 if(ch==' ')
{
k[i]='\0';
printf("%s",strrev(k));
i=0;
 }
else
 {
  k[i]=ch;
  i++;
 }
}
k[i]='\0';
printf("%s",strrev(k));
getch();
}
void push(char ch)
{
if(top==max-1)
{
 printf("\n Stack is full");
}
else
{
 top++;
 stack[top]=ch;
}
}

char pop()
{
char t;
if(top==-1)
{
 printf("\n Stack is Empty");
}
else
{
 t=stack[top];
 top--;
 return(t);
}
}

Monday, April 6, 2015

C program for binary search

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],n,i,k,mid,s,e,f=0;
 clrscr();
 printf("\n Enter how many number u want:-");
 scanf("%d",&n);
 printf("\n Please enter %d sorted numbers:-",n);
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 printf("\n numbers are:-");
 for(i=0;i<n;i++)
 {
  printf("\t%d",a[i]);
 }
 printf("\n\n Enter search key number:-\n");
 scanf("%d",&k);
 s=0;
 e=n-1;
 while(s<=e)
 {
  mid=(s+e)/2;
  if(k==a[mid])
  {
   printf("\n %d number is found on %d position.",k,mid+1);
   f=1;
   break;
  }
  else
  {
   if(k>a[mid])
   {
    s=mid+1;
   }
   else
   {
    e=mid-1;
   }
  }
 }
 if(f==0)
 {
  printf("\n number is not found");
 }
 getch();
}



/* OUTPUT
 Enter how many number u want:-5                                              
                                                                               
 Please enter 5 sorted numbers:-10 11 12 13 14                                
                                                                               
 numbers are:-  10      11      12      13      14                            
                                                                               
 Enter search key number:-                                                    
 12                                                                            
                                                                               
 12 number is found on 3 position.   */

C program for linear searching

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],n,i,k,f=0;
 clrscr();
 printf("\n Enter how many number u want:-");
 scanf("%d",&n);
 printf("\n Enter %d numbers:-",n);
 for(i=0;i<n;i++)
 {
  scanf(" %d",&a[i]);
 }
 printf("\n numbers are:-\n");
 for(i=0;i<n;i++)
 {
  printf("\t%d",a[i]);
 }
 printf("\n Enter search key number:-");
 scanf("%d",&k);
 for(i=0;i<n;i++)
 {
  if(k==a[i])
  {
   printf("\n %d number is found on %d position.",k,i+1);
   f=1;
   break;
  }
 }
 if(f==0)
 {
  printf("\n Number is not found");
 }
 getch();
}
/*
 Enter how many number u want:-5                                              
                                                                               
 Enter 5 numbers:-4 6 8 9 14                                                  
                                                                               
 numbers are:-                                                                
        4       6       8       9       14                                    
 Enter search key number:-9                                                    
                                                                               
 9 number is found on 4 position.      */

C program in data structure to make circular linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
void create();
void display();
void addbeg();
void addlast();
struct node
{
 int info;
 struct node *link;
}*start=NULL;
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**\n");
  printf("\n 1. to create list \n 2. to display list");
  printf("\n 3. to add node at beginning of linked list");
  printf("\n 4. to add node at the last of linked list");
  printf("\n 5. exit");
  printf("\n Enter your choice:-");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : create();
   break;
   case 2 : display();
   break;
   case 3 : addbeg();
   break;
   case 4 : addlast();
   break;
   case 5 : exit(0);

  }
 }
 getch();
}

void create()
{
 struct node *temp,*q;
 int x;
 temp=(struct node *)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start==NULL)
  {
   start=temp;
  }
  else
  {
   q=start;
   while(q->link!=start)
   {
    q=q->link;
   }
   q->link=temp;
  }
  temp->link=start;
 }
}

void display()
{
  struct node *q;
  printf("\n Circular linked list is:-\n\n");
  q=start;
  while(q->link!=start)
  {
   printf("   %d",q->info);
   q=q->link;
  }
  printf("   %d",q->info);
}

void addbeg()
{
 int x;
 struct node *temp,*q;
 temp=(struct node*)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;

  q=start;
  while(q->link!=start)
  {
   q=q->link;
  }
  temp->link=start;
  start=temp;
  q->link=start;
 }
}
void addlast()
{
 struct node *temp,*q;
 int x;
 temp=(struct node*)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;

  q=start;
  while(q->link!=start)
  {
   q=q->link;
  }
  q->link=temp;
  temp->link=start;
 }
}

C program in data structure to find the intersection between two linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
struct node
{
 int info;
 struct node *link;
}*start1=NULL,*start2=NULL;
void main()
{
 struct node *temp,*q,*p;
 int n,i,x,f=0;
 clrscr();
 printf("\n First linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start1==NULL)
  {
   start1=temp;
  }
  else
  {
   q=start1;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n first list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 start2=NULL;
 printf("\n Second linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start2==NULL)
  {
   start2=temp;
  }
  else
  {
   q=start2;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n second list\n");
 q=start2;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 printf("\n intersection of two list is:-\n");
 q=start1;
 while(q!=NULL)
 {
  p=start2;
  while(p!=NULL)
  {
   if(q->info==p->info)
   {
    printf("\t%d",q->info);
   }
   p=p->link;
  }
  q=q->link;
 }
 getch();
}

/*   OUTPUT
 First linked list                                                            
 Enter How many number:-5                                                      
                                                                               
 Enter number:-1                                                              
                                                                               
 Enter number:-2                                                              
                                                                               
 Enter number:-3                                                              
                                                                               
 Enter number:-4                                                              
                                                                               
 Enter number:-5                                                              
                                                                               
 first list                                                                    
        1       2       3       4       5                                      
 Second linked list                                                            
 Enter How many number:-4

 Enter number:-1

 Enter number:-2

 Enter number:-5

 Enter number:-6

 second list
1       2       5       6
 intersection of two list is:-
1       2       5            
*/

C program in data structure to reverse the singly linked list

/* Reverse the singly linked list */

#include<stdio.h>
#include<conio.h>
#include<process.h>
struct node
{
 int info;
 struct node *link;
}*start=NULL;
void main()
{
 struct node *temp,*q,*p,*t;
 int n,i,x;
 clrscr();
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start==NULL)
  {
   start=temp;
  }
  else
  {
   q=start;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 t=NULL;
 for(i=0;i<n;i++)
 {
  q=start;
  while(q->link!=t)
  {
   q=q->link;
  }
  t=q;
  printf("\n %d",q->info);
 }
 getch();
}


/* OUTPUT
 Enter How many number:-5                                                      
                                                                               
 Enter number:-1                                                              
                                                                               
 Enter number:-2                                                              

 Enter number:-3                                                              
                                                                               
 Enter number:-4                                                              
                                                                               
 Enter number:-5                                                              
                                                                               
 5                                                                            
 4                                                                            
 3                                                                            
 2
 1              

C program in data structure for concatenate two linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
struct node
{
 int info;
 struct node *link;
}*start1=NULL,*start2;
void main()
{
 struct node *temp,*q;
 int n,i,x;
 clrscr();
 printf("\n First linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start1==NULL)
  {
   start1=temp;
  }
  else
  {
   q=start1;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n first list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 start2=NULL;
 printf("\n Second linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start2==NULL)
  {
   start2=temp;
  }
  else
  {
   q=start2;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n second list\n");
 q=start2;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }

 q=start1;
 while(q->link!=NULL)
 {
      //concatenate two linked list
  q=q->link;
 }
 q->link=start2;
 printf("\n After concatenate linked list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 getch();
}

RDBMS example for project with different quiries

SQL> create table project
  2  (pno number(5) primary key,
  3  pname varchar2(20),
  4  status varchar2(5)
  5  check (status in('c','p','i')));

Table created.
SQL> insert into project values (&pno,'&pname','&status');
SQL> select * from project;

       PNO PNAME                STATU
---------- -------------------- -----
        11 voice_recognition    i
        12 speech_recognition   c
        13 video_recognition    i
        14 steganography        p
        15 cryptography         i

SQL> create table dept
  2  (deptno number(5) primary key,
  3  deptname varchar2(20),
  4  HOD varchar2(20),
  5  location varchar2(20));

Table created.
SQL> insert into dept values (&deptno,'&deptname','&HOD','&location');
SQL> select * from dept;

    DEPTNO DEPTNAME             HOD                  LOCATION
---------- -------------------- -------------------- --------------------
         1 mathematics          vijay                pune
         2 computer             ranjit               pune
         3 chemical             rahul                nasik
         4 civil                ajay                 nagpur
         5 IT                   santosh              nanded

SQL> create table dep_pro
  2  (deptno number(5) references dept,
  3  pno number(5) references project,
  4  primary key (deptno,pno));

Table created.
SQL> insert into dep_pro values (&deptno,&pno);
SQL> select * from dep_pro;

    DEPTNO        PNO
---------- ----------
         1         11
         2         12
         3         13
         4         14
         5         15





Queries:-

1 Find HOD of computer Department located in ‘Pune’.
SQL> select HOD from dept
  2  where deptname='computer' and location='pune';

HOD
--------------------
Ranjit

2 List all projects of mathematics department which are Incomplete.
  SQL>select project.*
from dept,project
where dept.deptno=project.deptno and statu='i'
and deptname='mathmatics';
 
  PNO      PNAME                     STATU
---------- --------------------             -----
  11        voice_recognition             i



3 Display the Project details of Computer Department.
SQL>select project.*
from dept,project
where dept.deptno=project.deptno and deptname='Computer';
       PNO PNAME              
---------- --------------------
        12 speech_recognition  

4 List department wise project along with status.

SQL> select deptname,pname,status from project,dept,dep_pro
  2  where project.pno=dep_pro.pno and
  3  dep_pro.deptno=dept.deptno
  4  group by deptname,pname,status;

DEPTNAME             PNAME                STATU
-------------------- --------------------         -----
IT                   cryptography                    i
chemical             video_recognition       i
civil                steganography                 p
computer             speech_recognition    c
mathematics          voice_recognition    c

C program in data structure in queue for character DMA Queue

C program in data structure in queue. For character DMA Queue

#include<stdio.h>
#include<conio.h>
#include<process.h>
void insert();
void deletes();
void display();
struct node
{
 char info;
 struct node *link;
}*front=NULL,*rear=NULL;
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**\n");
  printf("\n 1. insert \n 2. deletes");
  printf("\n 3. display \n 4. exit");
  printf("\n Enter your choice:- ");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : insert();
   break;
   case 2 : deletes();
   break;
   case 3 : display();
   break;
   case 4 : exit(0);
  }
 }
 getch();
}

void insert()
{
 struct node *temp,*q;
 char x;
 temp=(struct node *)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter character:-");
  scanf("%c",&x);
  temp->info=x;
  temp->link=NULL;
  if(rear==NULL&&front==NULL)
  {
   rear=temp;
   front=temp;
  }
  else
  {
   q=rear;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
}

void deletes()
{
 struct node *q;
 if(front==NULL&&rear==NULL)
 {
  printf("\n Queue is empty");
 }
 else
 {
   front=rear;
   rear=front->link;
   printf("\n deleted node is %c",front->info);
   free(front);
 }
}

void display()
{
 struct node *q;
 if(front==NULL&&rear==NULL)
 {
  printf("\n Queue is empty");
 }
 else
 {
  front=rear;
  while(front!=NULL)
  {
   printf("\n %c",front->info);
   front=front->link;
  }
 }
}

C program in data structure for polynomial subtraction

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],b[10],c[10];
 int n,k,i,p,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n first polynomial");
 printf("\n enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  a[p]=coeff;
 }
 printf("\n second polynomial");
 printf("\n enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  b[p]=coeff;
 }
 for(i=0;i<10;i++)
 {
  c[i]=a[i]-b[i];
 }
 printf("\n polynomial subtraction is=");
 for(i=9;i>=0;i--)
 {
  if(c[i]!=0)
  {
   if(i!=0)
   {
    printf("%dx^%d+",c[i],i);
   }
   else
   {
    printf("%dx^%d",c[i],i);
   }
  }
 }
 getch();
}

C program for multiplication of two polynomial in data structure

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],b[10],c[10];
 int i,j,n,k,power,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n first polynomel");
 printf("\n enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n enter coefficient=");
  scanf("%d",&coeff);
  printf("\n enter power");
  scanf("%d",&power);
  a[power]=coeff;
 }
 printf("\n second polynomel");
 printf("\n enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n enter coefficient=");
  scanf("%d",&coeff);
  printf("\n enter power");
  scanf("%d",&power);
  b[power]=coeff;
 }
 for(i=9;i>=0;i--)
 {
  if(a[i]!=0)
  {
   for(j=9;j>=0;j--)
   {
    if(b[j]!=0)
    {
     c[i+j]=c[i+j]+a[i]*b[j];
    }
   }
  }
 }
 printf("\n our results is=");
 for(i=9;i>=0;i--)
 {
  if(c[i]!=0)
  {
   if(i!=0)
   {
    printf("%dx^%d+",c[i],i);
   }
   else
   {
    printf("%dx^%d",c[i],i);
   }
  }
 }
 getch();
}

C program in data structure for addition of two polynomial

#include<stdio.h>
#include<conio.h>
void show(int p[]);
void main()
{
 int a[10],b[10],c[10];
 int n,k,i,p,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n First polynomial");
 printf("\n Enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n Enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  a[p]=coeff;
 }
 printf("\n Second polynomial");
 printf("\n Enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n Enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  b[p]=coeff;
 }
 printf("\n First polynomial is:-\n\n");
 show(a);
 printf("\n Second polynomial is:-\n\n");
 show(b);
 for(i=0;i<10;i++)
 {
  c[i]=a[i]+b[i];
 }
 printf("\n Addition of two polynomials is=\n\n");
 show(c);
 getch();
}
void show(int p[])
{
  int i;
  for(i=9;i>0;i--)
  {
   if(p[i]!=0)
   {
    printf("%dx^%d+",p[i],i);
   }
  }
  printf("%d",p[i]);
}

C program in data structure for evaluation of polynomial

#include<stdio.h>
#include<conio.h>
#include<math.h>
int eval(int b[],int n,int x);
void main()
{
 int a[10],i,e,n,x;
 clrscr();
 for(i=0;i>10;i++)
 {
  a[i]=0;
 }
 printf("\n Enter number of term:-\n");
 scanf("%d",&n);
 printf("\n Enter co-efficient:-\n");
 for(i=n;i>=0;i--)
 {
  printf("\n Enter co-efficient for A[%d]:-",i);
  scanf("%d",&a[i]);
 }
 printf("\n Polynomial Expression is:-\n");
 for(i=n;i>0;i--)
 {
  if(a[i]!=0)
  {
   printf("%dx^%d+",a[i],i);
  }
 }
 printf("%d",a[i]);
 printf("\n Enter value for x:-\n");
 scanf("%d",&x);
 e=eval(a,n,x);
 printf("\n Evaluation of Polynomial is:-\t%d",e);
 getch();
}
int eval(int b[],int n,int x)
{
 int i,s=0;
 for(i=n;i>=0;i--)
 {
  s=s+b[i]*pow(x,i);
 }
 return(s);
}

C program in data structure of polynomial for implementation of malloc and realloc function

 IMPLEMENTATION OF MALLOC AND REALLOC FUNCTION

#include<stdio.h>
#include<conio.h>
void main()
{
  int s,i,newsize,*p;
  clrscr();
  printf("\n Enter size of an array:-");
  scanf("%d",&s);
  p=(int *)malloc(s*sizeof(int));
  printf("\n Enter the number:-\n");
  for(i=0;i<s;i++)
  {
    scanf("%d",&p[i]);
  }
  printf("\n Entered numbers are:- \n");
  for(i=0;i<s;i++)
  {
    printf(" %d",p[i]);
  }
  printf("\nEnter newsize of an array:-");
  scanf("%d",&newsize);
  p=(int *)realloc(p,newsize);
  printf("\n Enter the numbers for newsize:-\n");
  for(i=s;i<newsize;i++)
  {
    scanf("%d",&p[i]);
  }
  printf("\n All elements of an array is:-\n");
  for(i=0;i<newsize;i++)
  {
    printf(" %d",p[i]);
  }
  getch();
 }

C program in data structure for storage representation of 2-D array

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10][10],i,j,r,c;
 clrscr();
 printf("\n Enter row and column number:-");
 scanf("%d%d",&r,&c);
 printf("\n Enter %d*%d matrix:-",r,c);
 for(i=0;i<r;i++)
 {
  for(j=0;j<c;j++)
  {
   scanf("%d",&a[i][j]);
  }
 }
 printf("\n storage representation of 2-D array:-");
 for(i=0;i<r;i++)
 {
  for(j=0;j<c;j++)
  {
   printf("\n[%d][%d]= %d",i,j,a[i][j]);
  }
  printf("\n");
 }
 getch();
}



/* OUTPUT
 Enter row and column number:-3 3                                              
                                                                               
 Enter 3*3 matrix:-1 2 3                                                      
                   4 5 6                                                      
                   7 8 9                                                      
                                                                               
 storage representation of 2-D array:-                                        
[0][0]= 1                                                                      
[0][1]= 2                                                                      
[0][2]= 3                                                                      
                                                                               
[1][0]= 4                                                                      
[1][1]= 5                                                                      
[1][2]= 6                                                                      
                                                                               
[2][0]= 7                                                                      
[2][1]= 8                                                                      
[2][2]= 9                                                                      
     */

C program for preorder inorder postorder in data structure

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
struct node
{
 int info;
 struct node *llink;
 struct node *rlink;
}*root=NULL;
void insert();
void preorder(struct node *q);
void inorder(struct node *q);
void postorder(struct node *q);
int stack[10];
int top=-1;
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**");
  printf("\n 1.insert \n 2.preorder");
  printf("\n 3.inorder \n 4.postorder");
  printf("\n 5.exit");
  printf("\n enter your choice:-");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : insert();
   break;
   case 2 : preorder(root);
   break;
   case 3 : inorder(root);
   break;
   case 4 : postorder(root);
   break;
   case 5 : exit(0);
  }
 }
 getch();
}
void insert()
{
 struct node *temp,*q;
 int x,i,n;
 printf("\n\n enter how many nodes you want:-");
 scanf(" %d",&n);
 for(i=0;i<n;i++)
 {

  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
    printf("\n insufficient memory");
  }
  else
  {
   printf("\n\n enter number:-");
   scanf("%d",&x);
   temp->info=x;
   temp->llink=NULL;
   temp->rlink=NULL;
   if(root==NULL)
   {
    root=temp;
   }
   else
   {
    q=root;
    while(1)
    {
     if(temp->info==q->info)
     {
       printf("\n\n element already exist");
       break;
     }
     if(temp->info>q->info)
     {
      if(q->rlink==NULL)
      {
       q->rlink=temp;
       break;
      }
      q=q->rlink;
     }
     if(temp->info<q->info)
     {
      if(q->llink==NULL)
      {
       q->llink=temp;
       break;
      }
      q=q->llink;
     }
    }
   }
  }
 }
}
void preorder(struct node *q)
{
 top++;
 stack[top]=q;
 while(top!=-1)
 {
  q=stack[top];
  top--;
  if(q!=NULL)
  {
   printf("  %d->",q->info);
   top++;
   stack[top]=q->rlink;
   top++;
   stack[top]=q->llink;
  }
 }
}
void inorder(struct node *q)
{

  while(top!=-1||q!=NULL)
  {
   if(q!=NULL)
   {
    top++;
    stack[top]=q;
    q=q->llink;
   }
   else
   {
    q=stack[top];
    top--;
    printf(" %d->",q->info);
    q=q->rlink;
   }
  }
}


void postorder(struct node *q)
{
 int f[5];
 int top_p;
 stack[++top]=NULL;
 do
 {
  while(q!=NULL)
  {
   stack[++top]=q;
   f[top]=1;
   if(q->rlink!=NULL)
   {
    stack[++top]=q->rlink;
    f[top]=-1;
   }
   q=q->llink;
  }
  top_p=top;
  q=stack[top--];
  while(f[top_p]==1)
  {
   printf(" %d->",q->info);
   top_p=top;
   q=stack[top--];
  }
 }
  while(q!=NULL);

}

C program in data structure for tree

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
 int info;
 struct node *llink,*rlink;
}*root=NULL;
void create();
void node(struct node *q);
void degree(struct node *q);
void leaf(struct node *q);
void interior(struct node *q);
void child(struct node *q);
int no,l,in,ch,p;
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**");
  printf("\n 1.create a tree \n 2.count num of nodes");
  printf("\n 3.degree of tree \n 4.leaf nodes \n 5.interior nodes");
  printf("\n 6.childrens and parent \n 7.exit");
  printf("\n enter your choice:-\t");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : create();
   break;
   case 2 : node(root);
   printf("\n\n total nodes are:-  %d",no);
   break;
   case 3 : degree(root);
   break;
   case 4 : leaf(root);
   printf("\n\n leaf nodes is:-  %d",l);
   break;
   case 5 : interior(root);
   printf("\n\n interior nodes are:-  %d",in);
   break;
   case 6 : child(root);
   printf("\n\n childrean is:- %d and parents is:-  %d",ch,p);
   break;
   case 7 : exit(0);
  }
 }
}
void create()
{
 struct node *temp,*q;
 int x,n,i;
 printf("\nEnter how many nodes you want:-");
 scanf("  %d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node *)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n insufficient memory");
  }
  else
  {
   printf("\n enter number:- ");
   scanf(" %d",&x);
   temp->info=x;
   temp->llink=NULL;
   temp->rlink=NULL;
   if(root==NULL)
   {
    root=temp;
   }
   else
   {
    q=root;
    while(1)
    {
     if(temp->info==q->info)
     {
      printf("\n number is aleardy exist");
      break;
     }
     if(temp->info>q->info)
     {
      if(q->rlink==NULL)
      {
       q->rlink=temp;
       break;
      }
      q=q->rlink;
     }
     if(temp->info<q->info)
     {
      if(q->llink==NULL)
      {
       q->llink=temp;
       break;
      }
      q=q->llink;
     }
    }
   }
  }
 }
}
void node(struct node *q)
{
 if(q!=NULL)
 {
  node(q->llink);
  node(q->rlink);
  no=no+1;
 }
}
void degree(struct node *q)
{
 if(q!=NULL)
 {
  if(q->llink!=NULL&&q->rlink!=NULL)
  {
   printf("\n\n degree of %d node is:= 2",q->info);
  }
  if(q->llink!=NULL&&q->rlink==NULL)
  {
   printf("\n\n degree of %d node is:= 1",q->info);
  }
  if(q->llink==NULL&&q->rlink!=NULL)
  {
   printf("\n\n degree of %d node is:= 1",q->info);
  }
  if(q->llink==NULL&&q->rlink==NULL)
  {
   printf("\n\n degree of %d node is:= 0",q->info);
  }
  degree(q->llink);
  degree(q->rlink);
 }
}
void leaf(struct node *q)
{
 if(q!=NULL)
 {
  leaf(q->llink);
  leaf(q->rlink);
  if(q->llink==NULL||q->rlink==NULL)
  {
   l=l+1;
  }
 }
}
void interior(struct node *q)
{
 if(q!=NULL)
 {
  interior(q->llink);
  interior(q->rlink);
  if(q->llink!=NULL||q->rlink!=NULL)
  {
   in=in+1;
  }
 }
}
void child(struct node *q)
{
 if(q!=NULL)
 {
  child(q->llink);
  child(q->rlink);
  if(q->llink!=NULL||q->rlink!=NULL)
  {
   p=p+1;
  }
  if(q->llink==NULL||q->rlink==NULL)
  {
   ch=ch+1;
  }
 }
}

C program in data structure for mirror of a tree

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
struct node
{
 int info;
 struct node *llink;
 struct node *rlink;
}*root=NULL;
void insert();
void preorder(struct node *q);
void mirror(struct node *q);
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**");
  printf("\n 1.insert \n 2.preorder");
  printf("\n 3.mirror \n 4.exit");
  printf("\n enter your choice:-");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : insert();
     break;
   case 2 : printf("\n\n our tree in preorder \n\n");
     preorder(root);
     break;
   case 3 :
     mirror(root);
     printf("\n\n mirror image is:-\n\n");
     preorder(root);
     break;
   case 4 : exit(0);
  }
 }
 getch();
}




void insert()
{
 struct node *temp,*q;
 int x,i,n;
 printf("\n\n enter how many node you want:=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {

  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n insufficient memory");
  }
  else
  {
   printf("\n\n enter number:-");
   scanf("%d",&x);
   temp->info=x;
   temp->llink=NULL;
   temp->rlink=NULL;
   if(root==NULL)
   {
    root=temp;
   }
   else
   {
    q=root;
    while(1)
    {
     if(temp->info==q->info)
     {
      printf("\n\n element already exist");
      break;
     }
     if(temp->info>q->info)
     {
      if(q->rlink==NULL)
      {
       q->rlink=temp;
       break;
      }
      q=q->rlink;
     }
     if(temp->info<q->info)
     {
      if(q->llink==NULL)
      {
       q->llink=temp;
       break;
      }
      q=q->llink;
     }//end of if
    }//end of while
   }//end of else2
  }//end of else1
 }//end of for loop
}
void preorder(struct node *q)
{
 if(q!=NULL)
 {
  printf(" %d->",q->info);
  preorder(q->llink);
  preorder(q->rlink);
 }
}
void mirror(struct node *q)
{
 struct node *temp1;
 if(q!=NULL)
 {
  mirror(q->llink);
  mirror(q->rlink);
  temp1=q->llink;
  q->llink=q->rlink;
  q->rlink=temp1;
 }
}

Wednesday, April 1, 2015

C program in stack data structure for infix and postfix expression

#define max 50
#include<stdio.h>
#include<conio.h>
#include<process.h>
void push(char ch);
char pop();
char stack[max];
int top=-1;
int prec(char chr);
void main()
{
 char a[60],b[60],ch;
 int i,j,p,r,x,y,re;
 clrscr();
 printf("\n Enter Infix Expression:-\n");
 scanf("%s",&a);
 i=0;
 j=0;
 for(i=0;a[i]!='\0';i++)
 {
  switch(a[i])
  {
   case '^':
   case '$':
   case '*':
   case '/':
   case '+':
   case '-': p=prec(a[i]);
    while(top!=-1&&p<=prec(stack[top]))
    {
      b[j]=pop();
      j++;
    }
    push(a[i]);  //push operator into stack
    break;
   case '(': push(a[i]);
    break;

   case ')':
    do
    {
     ch=pop();
     if(ch!='(')
     {
      b[j]=ch;
      j++;
     }
    }while(ch!='(');
     break;
   default : b[j]=a[i];  //output exp
    j++;
  }
 }
 while(top!=-1)
 {
  b[j]=pop();  //last pop the all operators.
  j++;
 }
 b[j]='\0';
 printf("\n Postfix Expression Is:-\n %s",b);
 printf("\n Evaluation of the Postfix expression:-\n");
 i=0;
 while(b[i]!='\0')
 {
  if(b[i]>='0'&&b[i]<='9')
  {
   push(b[i]-48); //convert char into nuumber
  }
  else
  {
   y=pop(); //pop the two poerands and prefrom operation
   x=pop();
   switch(b[i])
   {
      case '+' : r=x+y;
break;
      case '-' : r=x-y;
break;
      case '*' : r=x*y;
break;
      case '/' : r=x/y;
break;
      case '$' :
      case '^' : r=pow(x,y);
break;
   }
   push(r); //push the result into stack
  }
  i++;
 }
 re=pop(); // at the last pop the result and display.
 printf("\n %d",re);
 getch();
}

int prec(char chr)
{
 switch(chr)   // check the priority of the operators.
 {
  case '$' :
  case '^' : return(5);
  case '*' :
  case '/' : return(4);
  case '+' :
  case '-' : return(3);
  case '(' : return(2);
 }
 return(0);
}
void push(char x)
{
  top++;
  stack[top]=x;
}
char pop()
{
 char y;
 y=stack[top];
 top--;
 return(y);
}



RDBMS example for one to many relationship

Q.).
         Customer (cno,cname,city)
         Account (ano,acc_type,balance)

          Relationships between  customer and account  is one-to-many.
 
         Constraints :-primary key,
                                 Balance should be>100

SQL> create table customer2
  2  ( cno number(5)primary key,
  3    cname varchar2(30),
  4    city varchar2(40)
  5  );
Table created.

SQL> insert into customer2
  2  values('&cno','&cname','&city');
Enter value for cno: 101
Enter value for cname: mahendra
Enter value for city: pali
old   2: values('&cno','&cname','&city')
new   2: values('101','mahendra','pali')
1 row created.
SQL> select * from customer2;

  CNO   CNAME   CITY
--------   -----------  ------------------
  101 mahendra       pali
  102 babulal          pune
 103 amit              mumbai

 CNO   CNAME   CITY
--------   -----------  ------------------
 104        raju                 pune
105          akash          Ajmer

SQL> create table account
  2  ( ano number(5)primary key,
  3    acc_type varchar2(20),
  4    balance number(5) check(balance>100),
  5    cno number(5)references customer2(cno)
  6  );
Table created.

SQL> insert into account
2 values('&ano','&acc_type','&balance','&cno');
SQL> select * from account;

       ANO ACC_TYPE                          BALANCE        CNO
---------- ------------------------------ ---------- ----------
      1201 saving                              13000        101
      1202 current                             20000        102
      1203 saving                              14000        103
      1204 saving                              50000        104
      1205 current                             14000        105
      1206 saving                              25000        104
      1207 current                             19000        105


B). wirte a cursor to add interest of 3% to the balance of all account whose balance is greater than 10000.

  1  declare
  2     cursor c1 is select ano from account
  3     where balance>10000;
  4  begin
  5     for x in c1 loop
  6       update account
  7       set balance=balance+balance*3/100
  8       where ano=x.ano;
  9       commit;
 10     end loop;
 11* end;
SQL> /
PL/SQL procedure successfully completed.

SQL> select * from account;

       ANO ACC_TYPE                          BALANCE        CNO
---------- ------------------------------ ---------- ----------
      1201 saving                              13390        101
      1202 current                             20600        102
      1203 saving                              14420        103
      1204 saving                              51500        104
      1205 current                             14420        105
      1206 saving                              25750        104
      1207 current                             19570        105

7 rows selected.


a). create  or replace a PL/ SQL procedure to find total balance of all customers of pune city.
  1  create or replace procedure dis(x in varchar)
  2  is
  3      b number(20);
  4  begin
  5      select sum(a.balance) into b from customer2 c,
  6      account a where c.cno=a.cno and
  7      c.city=x;
  8        dbms_output.put_line('total balance of all customers of pune city:-'||b);
  9* end;
 10  /

Procedure created.

SQL> declare
  2
  3  begin
  4    dis('pune');
  5  end;
  6  /
total balance of all customers of pune city:-97850

PL/SQL procedure successfully completed.




RDBMS example of many to many relationship

Q.).    book ( bno, bname, pubname, price)
 
         Author ( ano, aname)
 
         Relationships between book and author is many to many.

         Constraints:-primary key,
                                Aname and pubname should NOT NULL.


SQL> select * from book_1;

       BNO BNAME                PUBNAME                             PRICE
---------- -------------------- ------------------------------ ----------
       101 C++                           nirali                                150
       102 M A/C                      vision                                250
       103 RDBMS                    BPB                                   175
       104 data structre              BPB                                   165
       105 software engineering   nirali                                135

SQL> select * from author;

       ANO ANAME
---------- --------------------
      1201  mr.dewasi
      1202  mr.shiravi b
      1203  mr.pankaj
      1204  kanetkar
      1205  babulal

SQL> select * from bookauth;

    BNO        ANO
---------- ----------
       101       1201
       102       1202
       103       1203
       104       1204
       102       1204
       105       1205
       101       1203

7 rows selected.


************************************************************************
a). create or replace a PL/SQL procedure to display details of all books written by ‘kanetkar’.

SQL>
  1  create or replace procedure disa(t in varchar2)
  2  is cursor ca is select b.bno,b.bname,b.pubname,b.price from book_1 b,
  3     author a, bookauth ba where b.bno=ba.bno and a.ano=ba.ano and
  4     a.aname=t;
  5  begin
  6     for x in ca loop
  7        dbms_output.put_line(x.bno||' '||x.bname||' '||x.pubname||' '||x.price);
  8     end loop;
  9* end;
SQL> /

Procedure created.

SQL>
  1  declare
  2  begin
  3     disa('kanetkar');
  4* end;
  5  /
104 data structre  BPB 165
102 M A/C vision 250

PL/SQL procedure successfully completed.


************************************************************************

b). create or replace a trigger that restricts insertion or updation of books having price less than 0.

SQL>
  1  create or replace trigger ta1
  2  before insert or update
  3  on book_1
  4  for each row
  5  declare
  6    p book_1.price%type;
  7  begin
  8    p:=:new.price;
  9    if(p<0) then
 10      raise_application_error(-20089,'book price must be>0');
 11    end if;
 12* end;
SQL> /

Trigger created.

SQL> insert into book_1
  2  values(106,'SE','nirali',-45);
insert into book_1
            *
ERROR at line 1:
ORA-20089: book price must be>0
ORA-06512: at "SCOTT.TA1", line 6
ORA-04088: error during execution of trigger 'SCOTT.TA1'


SQL> update book_1
  2  set price=-45
  3  where bno=101;
update book_1
       *
ERROR at line 1:
ORA-20089: book price must be>0
ORA-06512: at "SCOTT.TA1", line 6
ORA-04088: error during execution of trigger 'SCOTT.TA1'

************************************************************************

RDBMS example of book and dept many to one relationship

Q.) Book( bno, bname, pudname, price)

        Department( dno, dname)

        Relationships between book and department is many to one.
   
        Constraints:-primary key,  Price should bo>0.

SQL> select * from department_1;
    DNO DNAME
---------- ------------------------------
       101 computer
       102 science
       103 arts
       104 MBA
       105 MSC
SQL> select * from books_1;
 BNO     BNAME   PUBNAME    PRICE  DNO
-------   -------------  ---------------   --------- --------
201      C++              nirali               150      101
1202    numerical     BPB                180      102
             method  
1203     RDBMS     vision               140      101


  BNO     BNAME   PUBNAME    PRICE  DNO
-------   -------------  ---------------   --------- --------
1204    data structure       nirali          145       104
1205     social sic         vision            120      105
1206       POM              BPB             130      103

6 rows selected.
************************ ** ** ******************************************

a).create or replace a PL/SQL function to return total expenditure on books of a given department.

SQL>
  1  create or replace function disb(x in varchar2)return number
  2  is
  3    c number(5);
  4  begin
  5    select sum(b.price) into c from department_1 d,books_1 b
  6    where d.dno=b.dno and d.dname=x;
  7    return(c);
  8* end;
SQL> /
Function created.

SQL>
  1  declare
  2     dn department_1.dname%type;
  3     t number(10);
  4  begin
  5     dn:='&dn';
  6     t:=disb(dn);
  7     dbms_output.put_line('total expenditure on books of a'||' '||dn||' '||'is:-'||t);
  8* end;
SQL> /
Enter value for dn: computer
old   5:    dn:='&dn';
new   5:    dn:='computer';
total expenditure on books of a computer is:-290

PL/SQL procedure successfully completed.


************************************************************************
************************************************************************

b). write a cursor to display details of all books brought for a ‘computer’ department.

SQL>
  1  declare
  2    cursor c8 is select b.bno,b.bname,b.pubname,b.price from department_1 d,
  3    books_1 b where d.dno=b.dno and d.dname='computer';
  4  begin
  5    for x in c8
  6    loop
  7      dbms_output.put_line(x.bno||' '||x.bname||' '||x.pubname||' '||x.price);
  8    end loop;
  9* end;
SQL> /
1201 C++ nirali 150
1203 RDBMS vision 140

PL/SQL procedure successfully completed.


************************************************************************

रघुपति राघव राजाराम पतित पावन सीताराम ॥

 रघुपति राघव राजाराम पतित पावन सीताराम ॥ सुंदर विग्रह मेघश्याम गंगा तुलसी शालग्राम ॥ भद्रगिरीश्वर सीताराम भगत-जनप्रिय सीताराम ॥  जानकीरमणा स...