Posts

Showing posts from April, 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...

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 mi...

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]==']'&...

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) { ...

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...

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                                                  ...

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; ...

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;   } ...

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<...

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;   }  } ...

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....

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")...

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)    {  ...

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--)    {   ...

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...

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                                                                                             ...

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() { ...

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(roo...

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);   } ...

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...

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 ...

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   ...

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         ...