Monday, 3 November 2014

Network Encoding Techniques using NRZ, NRZI and Manchester C++ code

#include<iostream>
using namespace std;
int main(){
    bool bit[20];int i,n;
    char t='L';
    cout<<"\nEnter the  total bit size:";
    cin>>n;
    cout<<"\nEnter the bits with spaces:";
    for(i=0;i<n;i++){
        cin>>bit[i];
    }
    cout<<"\nNRZ          ";
    for(i=0;i<n;i++){
        if(bit[i]==0)
        cout<<"L ";
        else
        cout<<"H ";
        }
        cout<<"\n\nNRZI         ";
        cout<<"L ";
        for(i=1;i<n;i++){
            if(bit[i]==1)
            {
                if(t=='H')
                {
                    t='L';
                }
                else
                    t='H';
            }
            cout<<t<<" ";
        }

cout<<"\nMANCHASTER   ";
    for(i=0;i<n;i++){
        if(bit[i]==0)
        cout<<"LH";
        else
        cout<<"HL";
        }

     

    return 0;
}

Implementation of Doubly Link List with addition of nodes C++ code

#define DELAY 150000000
#include<iostream>
using namespace std;
#include<stdlib.h>
int count;
void swap();
void visual();
void delay();
class dll
{
    public:
    int data;
    class dll *next,*prev;
}*first,*last,*pf,*pl,*qf,*ql,*xf,*temp;

int main()
{
    visual();
    int c;
     char ch='y';
     while(ch=='y'|| ch=='Y')
    {
    system("cls");
    cout<<"\nOPERATIONS:\n1:ADD NODE\n2:DISPLAY DOUBLY LIST\n\nYour choice:";
    cin>>c;

    switch(c)
    {
        case 1:{

                    if(first==nullptr)
                    {
                        first=new dll;
                        cout<<"Enter data to node "<<++count<<" : ";
                        cin>>first->data;
                        first->prev=nullptr;
                        first->next=nullptr;
                        last=first;
                    }
                    else
                    {
                        temp=new dll;
                        cout<<"Enter data to node "<<++count<<" : ";
                        cin>>temp->data;
                        temp->prev=last;
                        last->next=temp;
                        temp->next=nullptr;
                        last=temp;
                        temp=nullptr;
                    }
                }
              break;

        case 2:{
                    if(count==0)
                    {
                        cout<<"\n\a\aEmpty List!!";
                        break;
                    }
                    system("cls");
                    cout<<"\nList Details before swapping:->>\n\n";
                    temp=first;
                    cout<<"\nElement   Current Address   Next Address   Previous Address\n\n";
                    for(int i=0;i<count;i++,temp=temp->next)
                    {
                    cout<<"  "<<temp->data<<"         "<<temp<<"          "<<temp->next<<"               "<<temp->prev;
                    cout<<endl<<endl;
                    }

                    cout<<"swapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswap";
                    swap();
                    cout<<"\n\nList Details after swapping:->>\n\n";
                    temp=first;
                    cout<<"\nElement   Current Address   Next Address   Previous Address\n\n";
                    for(int i=0;i<count;i++,temp=temp->next)
                    {
                    cout<<"  "<<temp->data<<"         "<<temp<<"          "<<temp->next<<"               "<<temp->prev;
                    cout<<endl<<endl;
                    }
               }
               break;

        default:cout<<"\nWrong entry!!";

    }
     cout<<"\a\nWANT TO CONTINUE?(Y/N):";
     cin>>ch;
    }
    return 0;
}

void swap()
{
                    pl=first;
                    ql=last;
                    pf=pl;
                    qf=ql;
                    if(count==2 || count==3)
                    {
                        pf->prev=pf->next;
                        pf->next=nullptr;
                        qf->next=qf->prev;
                        qf->prev=nullptr;
                        first=qf;
                        last=pf;
                        return;

                    }
                    while((pf->next)!=(qf->prev) && (pf->next)!=qf)
                    {
                        pl=pl->next;
                        ql=ql->prev;

                        if(pf==first)
                        {
                            pl->prev=qf;
                            qf->next=pl;
                            qf->prev=nullptr;
                            first=qf;

                            ql->next=pf;
                            pf->prev=ql;
                            pf->next=nullptr;
                            last=pf;
                        }
                        else
                        {
                            pl->prev=qf;
                            (pf->prev)->next=qf;

                            ql->next=pf;
                            (qf->next)->prev=pf;

                            qf->prev=pf->prev;
                            pf->next=qf->next;

                            pf->prev=ql;
                            qf->next=pl;

                        }
                        pf=pl;
                        qf=ql;
                    }

                    if(count%2==0)
                    {
                    pf=pl->prev;
                    qf=ql->next;

                    pl->next=qf;
                    pl->prev=ql;

                    ql->next=pl;
                    ql->prev=pf;

                    pf->next=ql;
                    qf->prev=pl;
                    }

                    else
                    {
                    xf=pl->next;
                    pf=pl->prev;
                    qf=ql->next;

                    pl->next=qf;
                    pl->prev=xf;

                    ql->next=xf;
                    ql->prev=pf;

                    pf->next=ql;
                    qf->prev=pl;

                    xf->prev=ql;
                    xf->next=pl;
                    }
}

void visual()
{
    system("cls");
    cout<<"LOADING,PLEASE WAIT";
    for(int j=0;j<8;j++)
    {
    cout<<".\a";
    delay();
    }
}
void delay()
{
    for(int i=0;i<DELAY;i++)
    continue;
}

Dijkstra's algorithm C++ code

# define SIZE 8
# define INFINITY 99
#include<iostream>
#include<stdlib.h>
using namespace std;
void build(int n);
void minimum(char key);
void table();
void print();
int n,c,mini,y,m;
int mat[SIZE][SIZE];
char name[SIZE];
struct adjac
{
    char node,k,hv;
    int dv,frend[7];
}ob[SIZE];

int main()
{
    cout<<"\nEnter the number of nodes:";
    cin>>n;
    build(n);
    table();
    system("cls");
    print();
}

void build(int n)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        cout<<"\nEnter the name of node "<<i+1<<" : ";
        cin>>name[i];
        ob[i].node=name[i];
        ob[i].dv=0;
        ob[i].hv='-';
        ob[i].k='F';
    }

    for(i=0;i<n;i++)
    {
        c=0;
        for(j=0;j<n;j++)
        {
            cout<<"\nEnter weight from node "<<name[i]<<" to node "<<name[j]<<" : ";
            cin>>mat[i][j];
            if(mat[i][j]!=0 && mat[i][j]!=INFINITY)
            {
                ob[i].frend[c++]=j;
            }
        }
         ob[i].frend[c]=-1;
         mat[i][i]=0;
    }
}

void table()
{
    int i,c,j;
    char key;
    cout<<"\nEnter the name of the key node:";
    cin>>key;
    minimum(key);
    for(j=0;j<n-1;j++)
    {
        minimum(ob[mini].node);
    }
}

void minimum(char key)
{
    int i;
     for(i=0;i<n;i++)
    {
        if(ob[i].k=='F')
        {
        if(ob[i].node==key)
        {
            ob[i].k='T';
            c=0;
            while(ob[i].frend[c]!=-1)
            {
                if(ob[ob[i].frend[c]].k=='F')
                {
                ob[ob[i].frend[c]].hv=ob[i].node;
                if(m++==c)
                ob[ob[i].frend[c]].dv+=mat[i][ob[i].frend[c]];
                else
                if(ob[ob[i].frend[c]].dv>ob[i].dv+mat[i][ob[i].frend[c]] || ob[ob[i].frend[c]].dv==0)
                ob[ob[i].frend[c]].dv=ob[i].dv+mat[i][ob[i].frend[c]];
                }
                c++;
            }
            break;
        }
        }
    }
    y=0;
    for(i=0;i<n;i++)
    {
    if(ob[i].dv!=0 && ob[i].k=='F')
    {
        if(y++==0)
        mini=i;
        if(ob[i].dv<ob[mini].dv)
        mini=i;
    }
    }
}

void print()
{
    int i;
    cout<<"\nNode       K            dv           hv\n\n";
    for(i=0;i<n;i++)
    {
        cout<<ob[i].node<<"          "<<ob[i].k<<"            "<<ob[i].dv<<"            "<<ob[i].hv<<endl<<endl;
    }

}

Binary Search trees (BST) Array representation C++ code

#include<iostream>
using namespace std;

struct BST
{
    int data,use;

}ob[100];

int main()
{
    int flag,a,b,index;
    char ch='y',c='y';
     for(int i=0;i<100;i++)
    {
        ob[i].data=0;
        ob[i].use=0;
    }
    cout<<"\nEnter the root element:";
    cin>>ob[0].data;
    ob[0].use=1;
     while(ch=='y' || ch=='Y')
    {
        flag=0;
        cout<<"\nEnter the element to push in BST:";
        cin>>a;
        if(a<ob[0].data)
        {
            if(ob[1].use!=1)
            {
                ob[1].data=a;
                ob[1].use=1;
            }
            else
            {
                   index=1;
                   while(flag!=1)
                   {
                       if(a<ob[index].data?index=2*index+1:index=2*index+2)
                       {
                           if(ob[index].use==0)
                           {
                            ob[index].data=a;
                            ob[index].use=1;
                            flag=1;
                           }
                       }
                   }
            }
        }
//****************************************************************
        else if(a>ob[0].data)
        {
            if(ob[2].use!=1)
            {
                ob[2].data=a;
                ob[2].use=1;
            }
            else
            {
                   index=2;
                   while(flag!=1)
                   {
                       if(a<ob[index].data?index=2*index+1:index=2*index+2)
                       {
                           if(ob[index].use==0)
                           {
                            ob[index].data=a;
                            ob[index].use=1;
                            flag=1;
                           }
                       }
                   }
            }
        }
        cout<<"\nWant to enter more elements in BST?(y/n):";
        cin>>ch;

    }
    cout<<"\n\n************************************************************************\n\n";
    while(c=='Y' || c=='y')
    {

        cout<<"\nEnter the index to display its data:";
        cin>>b;
        cout<<"\n->>"<<ob[b].data;
        cout<<"\nWant to enter more elements in BST?(y/n):";
        cin>>c;
    }
    return 0;
}

Binary Search Tree(BST) Array representation to Link List representation using zero index array

#include<iostream>
using namespace std;
#include<stdlib.h>

struct BST_Ar_L
{
    int data,dex;
    struct BST_Ar_L *left;
    struct BST_Ar_L *right;
}*root,*l,*r,*temp,*ctr;

int main()
{
    int a[100],t,index,m,n,key,flag=0;
    char ch='y';
    for(int i=0;i<99;i++)
    a[i]=-1;
    cout<<"\nEnter the elements of BST as per array implementation(starting from '0' index)\n";
    while(ch=='y' || ch=='Y')
    {
        cout<<"\nEnter the index of array:";
        cin>>t;
        cout<<"\nEnter the element of BST at that index:";
        cin>>a[t];
        cout<<"\nWant to enter more elements?(Y/N):";
        cin>>ch;
    }
    if(a[0]==-1)
    {
        cout<<"\nNo root element\nProgram will now exit...";
        return 0;
    }

    root=new BST_Ar_L;
    root->data=a[0];
    root->dex=0;
    root->left=NULL;
    root->right=NULL;

    if(a[1]!=-1)
    {
        l=new BST_Ar_L;
        l->data=a[1];
        l->dex=1;
        l->left=NULL;
        l->right=NULL;
        root->left=l;
    }
    if(a[2]!=-1)
    {
        r=new BST_Ar_L;
        r->data=a[2];
        r->dex=2;
        r->left=NULL;
        r->right=NULL;
        root->right=r;
    }
    index=3;
    while(index!=99)
    {
        if(a[index]==-1)
        {
        index++;
        continue;
        }
        else
        {
            temp=new BST_Ar_L;
            temp->data=a[index];
            if(index%2==1)
            {
                n=(index-1)/2;
                m=n;

                if(m%2==0)
                while(m!=1)
                m=(m-2)/2;
                else
                while(m!=2)
                m=(m-1)/2;

                    if(m==1)
                    ctr=l;
                    else
                    ctr=r;
                    while(ctr->dex!=n)
                    ctr=n%2?ctr->left:ctr->right;
                    index%2?ctr->left=temp:ctr->right=temp;
                    temp->dex=index;
                    temp->left=NULL;
                    temp->right=NULL;
            }
            else
            {

                n=(index-2)/2;
                m=n;

                if(m%2==0)
                while(m!=2)
                m=(m-2)/2;
                else
                while(m!=1)
                m=(m-1)/2;

                    if(m==1)
                    ctr=l;
                    else
                    ctr=r;

                    while(ctr->dex!=n)
                    n%2?ctr=ctr->left:ctr=ctr->right;
                    index%2?ctr->left=temp:ctr->right=temp;
                    temp->dex=index;
                    temp->left=NULL;
                    temp->right=NULL;

            }
             index++;
        }

    }
    system("cls");
    ch='y';
    while(ch=='y' || ch=='Y')
    {
    cout<<"\n********************************************************************************";
    cout<<"\n********************************************************************************\n";
    cout<<"\nEnter the element to display its details in BST:";
    cin>>key;
    flag=0;
    for(int i=0;i<100;i++)
    {
        if(a[i]==key)
        flag=1;
    }
    if(flag==1)
    {
    if(key==a[0])
    {
    cout<<"\nIt is the root element";
    if(a[1]!=-1 && a[2]!=-1)
    cout<<"\nRight Child="<<a[2]<<"\t\tLeft Child="<<a[1] ;
    else if(a[1]!=-1 && a[2]!=1)
    cout<<"\nRight Child=empty"<<"\t\tLeft Child="<<a[1] ;
    else
    cout<<"\nRight Child="<<a[2]<<"\t\tLeft Child=empty" ;
    }
    else
    {
        key<a[0]?ctr=l:ctr=r;
        temp=ctr;
        flag=0;
        while(flag!=1)
        {
            if(ctr->data==key)
            {
                if(ctr->dex==1 || ctr->dex==2)
                {
                if(ctr->right!=NULL && ctr->left!=NULL)
                cout<<"\nParent element="<<a[0]<<"\nRight Child="<<ctr->right->data<<"\t\tLeft Child="<<ctr->left->data;
                else if(ctr->right!=NULL && ctr->left==NULL)
                cout<<"\nParent element="<<a[0]<<"\nRight Child="<<ctr->right->data<<"\t\tLeft Child=empty";
                else if(ctr->right==NULL && ctr->left!=NULL)
                cout<<"\nParent element="<<a[0]<<"\nRight Child=empty"<<"\t\tLeft Child="<<ctr->left->data;
                else
                cout<<"\nParent element="<<a[0]<<"\nRight Child=empty"<<"\t\tLeft Child=empty";
                flag=1;
                }
                else
                {
                if(ctr->right!=NULL && ctr->left!=NULL)
                cout<<"\nParent element="<<temp->data<<"\nRight Child="<<ctr->right->data<<"\t\tLeft Child="<<ctr->left->data;
                else if(ctr->right!=NULL && ctr->left==NULL)
                cout<<"\nParent element="<<temp->data<<"\nRight Child="<<ctr->right->data<<"\t\tLeft Child=empty";
                else if(ctr->right==NULL && ctr->left!=NULL)
                cout<<"\nParent element="<<temp->data<<"\nRight Child=empty"<<"\t\tLeft Child="<<ctr->left->data;
                else
                cout<<"\nParent element="<<temp->data<<"\nRight Child=empty"<<"\t\tLeft Child=empty";
                flag=1;
                flag=1;
                }
            }
            else
                {
                    if(key<(ctr->data))
                    {
                        temp=ctr;
                        ctr=ctr->left;
                    }
                    else
                    {
                        temp=ctr;
                        ctr=ctr->right;
                    }
                }
        }
    }
    }
    else
    cout<<"\nElement not present in BST!!";
            cout<<"\nWant to display more elements?(Y/N):";
            cin>>ch;
    system("cls");
    }

}


Breadth First Search (BFS) and Depth First Search (DFS) C++ code

# define SIZE 10
#include<iostream>
#include<stdlib.h>
using namespace std;
void build(int n);
void process(int i);
char name[SIZE],que[SIZE];
int n,c,k,i,ptr=0,flag,h,select;
struct BFS
{
    char node;
    int frend[SIZE],index;

}ob[SIZE];


int main()
{
    cout<<"\nEnter the number of nodes:";
    cin>>n;
    build(n);
    que[0]=ob[0].node;
    k++;
    system("cls");
    cout<<"\n1:BFS\n2:DFS\nYour choice:";
    cin>>select;
    cout<<"Nodes          Queue Status";
    process(0);
    cout<<"\n\n\n";
}

void build(int n)
{
    int i,j,d;
    char temp;
    for(i=0;i<n;i++)
    {
        cout<<"\nEnter the name of node "<<i+1<<" : ";
        cin>>name[i];
        ob[i].node=name[i];
        ob[i].index=1;
    }

    for(i=0;i<n;i++)
    {
        c=0;

            cout<<"\nEnter number of adjacent nodes for node "<<name[i]<<" : ";
            cin>>c;
            for(d=0;d<c;d++)
            {
                cout<<"\nEnter adjacent node "<<d+1<<" : ";
                cin>>temp;
                for(int z=0;z<n;z++)
                {
                    if(ob[z].node==temp)
                    ob[i].frend[d]=z;
                }
            }

         ob[i].frend[d]=-1;
    }
}

void process(int i)
{

    if(ptr==k || k==-1)
    return;
    if(select==1)
    cout<<endl<<endl<<que[ptr];
    else
    cout<<endl<<endl<<ob[i].node;
    ob[i].index=3;
    c=0;
    while(ob[i].frend[c]!=-1)
    {
        flag=0;
        for(h=ptr;h<k;h++)
        {if(que[h]==ob[ob[i].frend[c]].node || ob[ob[i].frend[c]].index==3 )
        flag=1;}

        if(flag==0)
        {
        que[k++]=ob[ob[i].frend[c]].node;
        ob[ob[i].frend[c]].index=2;
        }
        c++;
    }
    cout<<"               ";
    if(select==1)
   {
    for(h=ptr+1;h<k;h++)
    {
        cout<<que[h]<<" , ";
    }
    for(i=0;i<n;i++)
    {
        if(que[ptr+1]==ob[i].node)
        break;
    }
    ptr++;
   }
   else
   {
        for(h=1;h<k;h++)
    {
        cout<<que[h]<<" , ";
    }
    for(i=0;i<n;i++)
    {
        if(que[k-1]==ob[i].node)
        break;
    }
    k--;
   }
    process(i);

}

C Program to perform all base conversions in Binary, Decimal, Hexadecimal & Octal number systems

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
void func1(int);
void func2(int);
void func3(int);
void func4(int);
void func5(int);
void func6(int);
void func7(char ar[],int);
void func8(char ar[],int);
void func9(char ar[],int);
void func10(int);
void func11(int);
void func12(int);
int a,c,sum=0,i,u,l;
main()
{     int ch,k,g=0;
      char cho='Y';
      printf("Welcome!!\n\a");
      while(toupper(cho)=='Y')
      {
      printf("\a\nPress->\n\n1:Binary to Decimal\n2:Decimal to Binary\n3:Octal to Decimal\n4:Decimal to Octal\n5:Octal to Binary\n6:Binary to Octal\n7:Hexadecimal to Decimal\n8:Hexadecimal to Binary\n9:Hexadecimal to Octal\n10:Binary to Hexadecimal\n11:Decimal to Hexadecimal\n12:Octal to Hexadecimal\n\n");
      printf("You pressed : ");
      scanf("%d",&ch);
      printf("\a");
      switch(ch)
      {
                case 1:{
                     printf("Enter Binary Number:");
                     scanf("%d",&a);
                     k=a;
                     while(k!=0)
                     {
                     if(k!=0)
                     {
                     if((k%10)!=0 && (k%10)!=1)
                     {
                     printf("\n\nYou entered a non Binary number!\n\a\a\a");
                     l=1;
                     break;
                     }
                     k/=10;
                     }
                     }
                     if(l!=1)
                     {
                     printf("\a");
                     func1(a);
                     }
                     }
                break;
                case 2:{
                     printf("Enter Decimal Number:");
                     scanf("%d",&a);
                     printf("\a");
                     func2(a);
                     }
                break;
                case 3:{
                     printf("Enter Octal Number:");
                     scanf("%d",&a);
                     k=a;
                     while(k!=0)
                     {
                     if(k!=0)
                     {
                     if((k%10)>7)
                     {
                     printf("\n\nYou entered a non Octal number!\n\a\a\a");
                     break;
                     }
                     k/=10;
                     }
                     else
                     {
                     printf("\a");
                     func3(a);
                     }
                     }
                     }
                break;
                case 4:{
                     printf("Enter Decimal Number:");
                     scanf("%d",&a);
                     printf("\a");
                     func4(a);
                     }
                break;
                case 5:{
                     printf("Enter Octal Number:");
                     scanf("%d",&a);
                     k=a;
                     while(k!=0)
                     {
                     if(k!=0)
                     {
                     if((k%10)>7)
                     {
                     printf("\n\nYou entered a non Octal number!\n\a\a\a");
                     break;
                     }
                     k/=10;
                     }
                     else
                     {
                     printf("\a");
                     func5(a);
                     }
                     }
                     }
                break;
                case 6:{
                     printf("Enter Binary Number:");
                     scanf("%d",&a);
                      k=a;
                     while(k!=0)
                     {
                     if(k!=0)
                     {
                     if((k%10)!=0 && (k%10)!=1)
                     {
                     printf("\n\nYou entered a non Binary number!\n\a\a\a");
                     l=1;
                     break;
                     }
                     k/=10;
                     }
                     }
                     if(l!=1)
                     {
                     printf("\a");
                     func6(a);
                     }
                     }
                break;
                case 7:{
                     char ar[5];
                     int n=0,j;
                     printf("Enter Hexadecimal Number:");
                     printf("\nEnter number of characters in Hexadecimal Number:");
                     scanf("%d",&n);
                     printf("\a");
                     fflush(stdin);
                     printf("\nEnter Hexadecimal characters separated with spaces:");
                     for(j=0;j<n;j++)
                     {
                     scanf("%s",&ar[j]);
                     printf("\a");
                     }
                     fflush(stdin);
                     u=-1;
                     while(ar[++u]!='\0')
                     {
                     if(toupper(ar[u])!='A' && toupper(ar[u])!='B' && toupper(ar[u])!='C' && toupper(ar[u])!='D' && toupper(ar[u])!='E' && toupper(ar[u])!='F' && ar[u]!='0' && ar[u]!='1' && ar[u]!='2' && ar[u]!='3' && ar[u]!='4' && ar[u]!='5' && ar[u]!='6' && ar[u]!='7' && ar[u]!='8' && ar[u]!='9')
                     {
                     printf("\n\nYou entered a non Hexadecimal number!\nProgram will now EXIT...\a\a\a");
                     getch();
                     return 0;
                     }
                     }
                     printf("\a");
                     func7(ar,n);
                     }
                break;
                case 8:{
                     char ar[5];
                     int n=0,j;
                     printf("Enter Hexadecimal Number:");
                     printf("\nEnter number of characters in Hexadecimal Number:");
                     scanf("%d",&n);
                     printf("\a");
                     printf("\nEnter Hexadecimal characters separated with spaces:");
                     for(j=0;j<n;j++)
                     {
                     scanf("%s",&ar[j]);
                     }
                     fflush(stdin);
                     u=-1;
                     while(ar[++u]!='\0')
                     {
                     if(toupper(ar[u])!='A' && toupper(ar[u])!='B' && toupper(ar[u])!='C' && toupper(ar[u])!='D' && toupper(ar[u])!='E' && toupper(ar[u])!='F' && ar[u]!='0' && ar[u]!='1' && ar[u]!='2' && ar[u]!='3' && ar[u]!='4' && ar[u]!='5' && ar[u]!='6' && ar[u]!='7' && ar[u]!='8' && ar[u]!='9')
                     {
                     printf("\n\nYou entered a non Hexadecimal number!\nProgram will now EXIT...\a\a\a");
                     getch();
                     return 0;
                     }
                     }
                     printf("\a");
                     func8(ar,n);
                     }
                break;
                case 9:{
                     char ar[5];
                     int n=0,j;
                     printf("Enter Hexadecimal Number:");
                     printf("\nEnter number of characters in Hexadecimal Number:");
                     scanf("%d",&n);
                     printf("\a");
                     printf("\nEnter Hexadecimal characters separated with spaces:");
                     for(j=0;j<n;j++)
                     {
                     scanf("%s",&ar[j]);
                     }
                     u=-1;
                     while(ar[++u]!='\0')
                     {
                     if(toupper(ar[u])!='A' && toupper(ar[u])!='B' && toupper(ar[u])!='C' && toupper(ar[u])!='D' && toupper(ar[u])!='E' && toupper(ar[u])!='F' && ar[u]!='0' && ar[u]!='1' && ar[u]!='2' && ar[u]!='3' && ar[u]!='4' && ar[u]!='5' && ar[u]!='6' && ar[u]!='7' && ar[u]!='8' && ar[u]!='9')
                     {
                     printf("\n\nYou entered a non Hexadecimal number!\nProgram will now EXIT...\a\a\a");
                     getch();
                     return 0;
                     }
                     }
                     printf("\a");
                     func9(ar,n);
                     }
                break;
                case 10:{
                     printf("Enter Binary Number:");
                     scanf("%d",&a);
                     k=a;
                      k=a;
                     while(k!=0)
                     {
                     if(k!=0)
                     {
                     if((k%10)!=0 && (k%10)!=1)
                     {
                     printf("\n\nYou entered a non Binary number!\n\a\a\a");
                     l=1;
                     break;
                     }
                     k/=10;
                     }
                     }
                     if(l!=1)
                     {
                     printf("\a");
                     func10(a);
                     }
                     }
                break;
                case 11:{
                     printf("Enter Decimal Number:");
                     scanf("%d",&a);
                     printf("\a");
                     func11(a);
                     }
                break;
                case 12:{
                     printf("Enter Octal Number:");
                     scanf("%d",&a);
                     k=a;
                     while(k!=0)
                     {
                     if((k%10)>7)
                     {
                     printf("\n\nYou entered a non Octal number!\n\a\a\a");
                     l++;
                     break;
                     }
                     k/=10;
                     }
                     if(l==0)
                     {
                     printf("\a");
                     func12(a);
                     }
                     }
                break;
                default:printf("\nYou Enetred A Wrong Choice!");
                }

               printf("\n\n\aWant to perform more conversions?(Y/N):");
               scanf("%s",&cho);
               printf("\a");
               system("cls");
               }
               return 0;
      }

void func1(a)
{
     while(a!=0)
     {
     sum+=pow(2,c++)*(a%10);
     a/=10;
     }
     printf("Decimal Equivalent is:%d",sum);
     }

void func2(a)
{
     int b[15],i,c=0;
     printf("Binary Equivalent:");
     while(a!=1)
     {
                b[c++]=a%2;
                a/=2;
                }
                b[c]=1;
                for(i=c;i>-1;i--)
                printf("%d",b[i]);
                }
void func3(a)
{
     while(a!=0)
     {
     sum+=pow(8,c++)*(a%10);
     a/=10;
     }
     printf("Decimal Equivalent is:%d",sum);
     }

void func4(a)
{
     int b[15],i,c=0;
     printf("Octal Equivalent:");
     while(a>7)
     {
                b[c++]=a%8;
                a/=8;
                }
                b[c]=a;
                for(i=c;i>-1;i--)
                printf("%d",b[i]);
                }

void func5(a)
{    int b[15],i;
     while(a!=0)
     {
     sum+=pow(8,c++)*(a%10);
     a/=10;
     }
     func2(sum);
     }

void func6(a)
{
     while(a!=0)
     {
     sum+=pow(2,c++)*(a%10);
     a/=10;
     }
    func4(sum);
     }

void func7(char ar[],int nr)
{    int i=0,sum=0;
     int c=-1;
     for(i=nr-1;i>-1;i--)
     {c++;
     if(toupper(ar[i])=='A')
     sum+=pow(16,c)*10;
     else if(toupper(ar[i])=='B')
     sum=pow(16,c)*11;
     else if(toupper(ar[i])=='C')
     sum=pow(16,c)*12;
     else if(toupper(ar[i])=='D')
     sum=pow(16,c)*13;
     else if(toupper(ar[i])=='E')
     sum=pow(16,c)*14;
     else if(toupper(ar[i])=='F')
     sum=pow(16,c)*15;
     else if(ar[i]=='1')
     sum+=pow(16,c)*1;
     else if(ar[i]=='2')
     sum+=pow(16,c)*2;
     else if(ar[i]=='3')
     sum+=pow(16,c)*3;
     else if(ar[i]=='4')
     sum+=pow(16,c)*4;
     else if(ar[i]=='5')
     sum+=pow(16,c)*5;
     else if(ar[i]=='6')
     sum+=pow(16,c)*6;
     else if(ar[i]=='7')
     sum+=pow(16,c)*7;
     else if(ar[i]=='8')
     sum+=pow(16,c)*8;
     else if(ar[i]=='9')
     sum+=pow(16,c)*9;
     }
     printf("Decimal Equivalent is:%d",sum);
     }

void func8(char ar[],int nr)
{    int i=0,sum=0;
     int c=-1;
     for(i=nr-1;i>-1;i--)
     {c++;
     if(toupper(ar[i])=='A')
     sum+=pow(16,c)*10;
     else if(toupper(ar[i])=='B')
     sum=pow(16,c)*11;
     else if(toupper(ar[i])=='C')
     sum=pow(16,c)*12;
     else if(toupper(ar[i])=='D')
     sum=pow(16,c)*13;
     else if(toupper(ar[i])=='E')
     sum=pow(16,c)*14;
     else if(toupper(ar[i])=='F')
     sum=pow(16,c)*15;
     else if(ar[i]=='1')
     sum+=pow(16,c)*1;
     else if(ar[i]=='2')
     sum+=pow(16,c)*2;
     else if(ar[i]=='3')
     sum+=pow(16,c)*3;
     else if(ar[i]=='4')
     sum+=pow(16,c)*4;
     else if(ar[i]=='5')
     sum+=pow(16,c)*5;
     else if(ar[i]=='6')
     sum+=pow(16,c)*6;
     else if(ar[i]=='7')
     sum+=pow(16,c)*7;
     else if(ar[i]=='8')
     sum+=pow(16,c)*8;
     else if(ar[i]=='9')
     sum+=pow(16,c)*9;
     }
     func2(sum);
     }

void func9(char ar[],int nr)
{    int i=0,sum=0;
     int c=-1;
     for(i=nr-1;i>-1;i--)
     {c++;
     if(toupper(ar[i])=='A')
     sum+=pow(16,c)*10;
     else if(toupper(ar[i])=='B')
     sum=pow(16,c)*11;
     else if(toupper(ar[i])=='C')
     sum=pow(16,c)*12;
     else if(toupper(ar[i])=='D')
     sum=pow(16,c)*13;
     else if(toupper(ar[i])=='E')
     sum=pow(16,c)*14;
     else if(toupper(ar[i])=='F')
     sum=pow(16,c)*15;
     else if(ar[i]=='1')
     sum+=pow(16,c)*1;
     else if(ar[i]=='2')
     sum+=pow(16,c)*2;
     else if(ar[i]=='3')
     sum+=pow(16,c)*3;
     else if(ar[i]=='4')
     sum+=pow(16,c)*4;
     else if(ar[i]=='5')
     sum+=pow(16,c)*5;
     else if(ar[i]=='6')
     sum+=pow(16,c)*6;
     else if(ar[i]=='7')
     sum+=pow(16,c)*7;
     else if(ar[i]=='8')
     sum+=pow(16,c)*8;
     else if(ar[i]=='9')
     sum+=pow(16,c)*9;
     }
     func4(sum);
     }
void func10(a)
{    char b[10];
     int k,i=0,c=0;
     while(a!=0)
     {
     k=a%10000;
     if(k==0)
     b[i++]='0';
     else if(k==1)
     b[i++]='1';
     else if(k==10)
     b[i++]='2';
     else if(k==11)
     b[i++]='3';
     else if(k==100)
     b[i++]='4';
     else if(k==101)
     b[i++]='5';
     else if(k==110)
     b[i++]='6';
     else if(k==111)
     b[i++]='7';
     else if(k==1000)
     b[i++]='8';
     else if(k==1001)
     b[i++]='9';
     else if(k==1010)
     b[i++]='A';
     else if(k==1011)
     b[i++]='B';
     else if(k==1100)
     b[i++]='C';
     else if(k==1101)
     b[i++]='D';
     else if(k==1110)
     b[i++]='E';
     else if(k==1111)
     b[i++]='F';
     a/=10000;
     }
     printf("Hexadecimal Equivalent:");
     for(i=i-1;i>-1;i--)
     {
     printf("\a");
     printf("%c",b[i]);
     }
     }

void func11(a)
{
     int b[15],i,c=0;
     while(a!=1)
     {
                b[c++]=a%2;
                a/=2;
                }
                b[c]=1;
                for(i=c;i>-1;i--)
                sum=sum*10+b[i];
                func10(sum);
                }

void func12(a)
{
     int b[15],m[15],i,c=0,sum=0,sum1=0;
     {
     while(a!=0)
     {
     sum+=pow(8,c++)*(a%10);
     a/=10;
     }
                c=0;
                while(sum!=1)
                {
                m[c++]=sum%2;
                sum/=2;
                }
                m[c]=1;
                for(i=c;i>-1;i--)
                sum1=(sum1*10)+m[i];
                func10(sum1);
                }

                }