Showing posts with label Programs. Show all posts
Showing posts with label Programs. Show all posts

Apr 2, 2011

Write a program to perform all operations on singly Circular linked list

#include
#include
struct abc
{
int info;
struct abc *link;
};
struct abc *f = NULL, *prev = NULL;
void main()
{
int ch;
do
{
clrscr();
printf("\n Linked list");
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete ");
printf("\n 4. Search");
printf("\n 5. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
getch();
continue;
case 2:
display();
getch();
continue;
case 3:
delete();
getch();
continue;
case 4:
search();
getch();
continue;
}
}while(ch!= 5);
}
insert()
{
struct abc *new;
new = (struct abc *) malloc(sizeof(struct abc));
printf("\n Enter value :");
scanf("%d",&new->info);
if(f==NULL && prev == NULL)
{
f=new;
prev= new;
new->link = f;
return;
}
prev->link = new;
new->link = f;
prev = new;
return;
}
display()
{
struct abc *x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
x=f;
do
{
printf("\n Value is : %d", x->info);
x = x->link;
}while(x!=f);
return;
}
delete()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to delete : ");
scanf("%d",&x);
if(f->info == x && f == prev)
{
f = NULL;
prev = NULL;
return;
}
if(f->info == x)
{
f = f->link;
prev->link = f;
return;
}
p=f;
do
{
q=p;
p=p->link;
}while(p!=f && p->info != x);

if(p->info == x && p == prev)
{
q->link = p->link;
prev = q;
return;
}
if(p->info == x)
{
q->link = p->link;
return;
}
printf("\n Element not found in the list ");
return;
}
search()
{

struct abc *p,*q;
int x,flag=0;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to search : ");
scanf("%d",&x);
p=f;
do
{
if(p->info == x)
{
flag = 1;
break;
}
p=p->link;
}while(p!= f);
if(flag)
printf("\n Element found in the list ");
else
printf("\n Element not found in the list ");
return;
}

Write a program to perform all operations on singly unordered linked list

#include
#include
struct abc
{
int info;
struct abc *link;
};
struct abc *f = NULL, *prev = NULL;
void main()
{
int ch;
do
{
clrscr();
printf("\n Linked list");
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete ");
printf("\n 4. Search");
printf("\n 5. Sort");
printf("\n 6. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
getch();
continue;
case 2:
display();
getch();
continue;
case 3:
delete();
getch();
continue;
case 4:
search();
getch();
continue;
case 5:
sort();
getch();
continue;
}
}while(ch!= 6);
}
insert()
{
struct abc *new;
new = (struct abc *) malloc(sizeof(struct abc));
printf("\n Enter value :");
scanf("%d",&new->info);
if(f==NULL && prev == NULL)
{
f=new;
prev= new;
new->link = NULL;
return;
}
prev->link = new;
new->link = NULL;
prev = new;
return;
}
display()
{
struct abc *x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
x=f;
while(x!=NULL)
{
printf("\n Value is : %d", x->info);
x = x->link;
}
return;
}
delete()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to delete : ");
scanf("%d",&x);
if(f->info == x && f == prev)
{
f = NULL;
prev = NULL;
return;
}
if(f->info == x)
{
f = f->link;
return;
}
p=f;
while(p!=NULL && p->info != x)
{
q=p;
p=p->link;
}
if(p->info == x && p == prev)
{
q->link = p->link;
prev = q;
return;
}
if(p->info == x)
{
q->link = p->link;
return;
}
printf("\n Element not found in the list ");
return;
}
search()
{

struct abc *p,*q;
int x,flag=0;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to search : ");
scanf("%d",&x);
p=f;
while(p!=NULL)
{
if(p->info == x)
{
flag = 1;
break;
}
p=p->link;
}
if(flag)
printf("\n Element found in the list ");
else
printf("\n Element not found in the list ");
return;
}
sort()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
for(p=f;p!=NULL;p=p->link)
{
for(q=p;q!=NULL;q=q->link)
{
if(p->info > q->info)
{
x = p->info;
p->info = q->info;
q->info = x;
}
}
}
display();
return;
}

Write a program to perform all operations on singly ordered linked list

#include
#include
struct abc
{
int info;
struct abc *link;
};
struct abc *f = NULL, *prev = NULL;
void main()
{
int ch;
do
{
clrscr();
printf("\n Linked list");
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete ");
printf("\n 4. Search");
printf("\n 5. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
getch();
continue;
case 2:
display();
getch();
continue;
case 3:
delete();
getch();
continue;
case 4:
search();
getch();
continue;
}
}while(ch!= 5);
}
insert()
{
struct abc *new,*p,*q;
new = (struct abc *) malloc(sizeof(struct abc));
printf("\n Enter value :");
scanf("%d",&new->info);
if(f==NULL && prev == NULL)
{
f=new;
prev= new;
new->link = NULL;
return;
}
if(new->info <=f->info)
{
new->link = f;
f=new;
return;
}
if(new->info >= prev->info)
{
prev->link = new;
new->link = NULL;
prev = new;
return;
}
p =f;
while(p->info <= new->info)
{
q=p;
p=p->link;
}
q->link = new;
new->link = p;
return;
}
display()
{
struct abc *x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
x=f;
while(x!=NULL)
{
printf("\n Value is : %d", x->info);
x = x->link;
}
return;
}
delete()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to delete : ");
scanf("%d",&x);
if(f->info == x && f == prev)
{
f = NULL;
prev = NULL;
return;
}
if(f->info == x)
{
f = f->link;
return;
}
p=f;
while(p!=NULL && p->info != x)
{
q=p;
p=p->link;
}
if(p->info == x && p == prev)
{
q->link = p->link;
prev = q;
return;
}
if(p->info == x)
{
q->link = p->link;
return;
}
printf("\n Element not found in the list ");
return;
}
search()
{

struct abc *p,*q;
int x,flag=0;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to search : ");
scanf("%d",&x);
p=f;
while(p!=NULL)
{
if(p->info == x)
{
flag = 1;
break;
}
p=p->link;
}
if(flag)
printf("\n Element found in the list ");
else
printf("\n Element not found in the list ");
return;
}

Mar 30, 2011

Program to implement all the operations on stack

#include<stdio.h>
#include<conio.h>
int stack[100],tos=-1;
void main()
{
    int ch;
    do
    {
        clrscr();
        printf("\n Stack ");
        printf("\n 1. PUSH");
        printf("\n 2. POP");
        printf("\n 3. PEEP");
        printf("\n 4. DISPLAY");
        printf("\n 5. Exit");
        printf("\n Enter your choice :");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                push();
                getch();
                continue;
            case 2:
                pop();
                getch();
                continue;
            case 3:
                peep();
                getch();
                continue;
            case 4:
                display();
                getch();
                continue;
        }
    }while(ch!=5);
}
push()
{
    int x;
    if(tos==99)
    {
        printf("\n Stack is Full");
        return;
    }
    printf("\n Enter value : ");
    scanf("%d",&x);
    stack[++tos] = x;
    return;
}
pop()
{
    int x;
    if(tos==-1)
    {
        printf("\n Stack is Empty");
        return;
    }
    x = stack[tos--];
    printf("\n Element popped ... %d",x);
    return;
}
peep()
{
    if(tos==-1)
    {
        printf("\n Stack is Empty");
        return;
    }
    printf("\n Element on top of the stack : %d",stack[tos]);
    return;
}
display()
{
    int x;
    if(tos==-1)
    {
        printf("\n Stack is Empty");
        return;
    }
    for(x=tos;x>=0;x--)
        printf("\n Element on stack[%d] is  : %d",x+1,stack[x]);
    return;
}


C Program For Bubble Short Method

#include<stdio.h>
#include<conio.h>
void main()
{
    int *p,i,n;
    clrscr();
    printf("\n How many elements to sort :");
    scanf("%d",&n);

    p=(int *) malloc(sizeof(int) *n);
    for(i=0;i<n;i++)
    {
        printf("\n Enter Value :" );
        scanf("%d",(p+i));
    }
    sort(p,n);
    getch();
}
sort(int *p,int n)
{
    int i,j,k;
    for(i=0;i<n;i++)
    {
        for(j=0;j<(n-1);j++)
        {
            if(*(p+j) > *(p+(j+1)))
            {
                k = *(p+j);
                *(p+j) = *(p+(j+1));
                *(p+(j+1)) = k;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("\n Value is  : %d",*(p+i));
    }
}

Program to create a binary tree and produce the output using all three traversal methods of binary tree.

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

struct abc
{
    int info;
    struct abc *left,*right;
};
struct abc *root = NULL, *node,*p,*q;
void main()
{
    int ch;
    do
    {
        clrscr();
        printf("\n Binary Tree");
        printf("\n 1. Insert element");
        printf("\n 2. Preorder Traversal");
        printf("\n 3. Inorder Traversal");
        printf("\n 4. Postorder Traversal");
        printf("\n 5. Exit");
        printf("\n Enter your choice :");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                insert();
                getch();
                continue;
            case 2:
                p = root;
                preorder(p);
                getch();
                continue;
            case 3:
                p = root;
                inorder(p);
                getch();
                continue;
            case 4:
                p = root;
                postorder(p);
                getch();
                continue;
        }
    }while(ch!=5);
}
insert()
{
    node = (struct abc *) malloc(sizeof(struct abc));
    printf("\n Enter element : ");
    scanf("%d",&node->info);
    if(root == NULL)
    {
        root = node;
        node->left = NULL;
        node->right = NULL;
        return;
    }
    p = root;
    find(p);
    return;
}
find( struct abc *p)
{
    if(node->info < p->info)
    {
        if(p->left != NULL)
            find(p->left);
        else
        {
            p->left = node;
            node->left = NULL;
            node->right = NULL;
            return;
        }
    }
    else if(node->info > p->info)
    {
        if(p->right != NULL)
            find(p->right);
        else
        {
            p->right = node;
            node->left = NULL;
            node->right = NULL;
            return;
        }
    }
    else
    {
        printf("\n Duplicate Element not allowed");
        return;
    }
    return;
}
preorder(struct abc *p)
{
    printf("\n Element is : %d",p->info);
    if(p->left != NULL)
        preorder(p->left);
    if(p->right != NULL)
        preorder(p->right);
    return;
}
inorder(struct abc *p)
{

    if(p->left != NULL)
        inorder(p->left);
    printf("\n Element is : %d",p->info);
    if(p->right != NULL)
        inorder(p->right);
    return;
}
postorder(struct abc *p)
{
    if(p->left != NULL)
        postorder(p->left);
    if(p->right != NULL)
        postorder(p->right);
    printf("\n Element is : %d",p->info);
    return;
}

C Program For The BinarySearch

#include<stdio.h>
#include<conio.h>
// Binary search
void main()
{
    int x[10],low,high,mid,y,i,j,k;
    clrscr();
    for(i=0;i<=9;i++)
    {
        printf("\n Enter value :");
        scanf("%d",&x[i]);
    }
    for(i<=0;i<=9;i++)
    {
        for(j=i+1;j<=9;j++)
        {
            if(x[i] > x[j])
            {
                k=x[i];
                x[i]=x[j];
                x[j] = k;
            }
        }
    }
    printf("\n Enter value to search :");
    scanf("%d",&y);
    high = 10;
    low =0;
    while(low <= high)
    {
        mid = (low + high) /2;
        if(y < x[mid])
            high = mid -1;
        else if(y>x[mid])
            low = mid +1;
        else
        {
            printf("\n Element found on %dth location ",mid+1);
            break;
        }
    }
}

Mar 26, 2011

Deleting value from a Linear Array at Specified Position.

# define s 20

char employ[s][s];
int delete_array(char employ[s][s], int, int, char *);
void input(char emply[s][s], int );
void display(char employ[s][s], int );

/* Definition of the function */

int delete_array(char employ[s][s], int number, int position, char element[])
{
int temp = position;
element = employ[position];
printf("\n Information which we have to delete: %s", element);

while( temp <= number-1)
{
*employ [temp] = *employ[temp+1];
temp ++;
}
number = number - 1 ;
return(number);
}

void input(char employ[s][s], int number)
{
int i;
for(i = 1; i<= number ; i++)
{
fflush(stdin);
printf("\n Input value for: %d: ", i);
gets(employ[i]);
}
}

void display(char employ[s][s], int number)
{
int i;
for(i = 1; i<= number; i++)
{
printf("\n Value at the position: %d: %s", i, employ[i]);
}
}

/* main function */

void main()
{
int number;
int position;
char element[s];

printf("\n Input the number of elements in the array:");
scanf("%d", &number);
fflush(stdin);
input(employ, number);
printf("\n Entered list is as follows:\n");

display(employ, number);
fflush(stdin);
printf("\n Input the position from where you want delete an element:");
scanf("%d", &position);

number = delete_array(employ, number, position, element);
display(employ,number);
}

Inserting value in a Linear Array at Specified Position.


int insert_array(char *, int, int, char);
void input(char *, int );
void display(char *, int );

/* Definition of the function */

int insert_array(char array[], int number, int position, char element)
{
int temp = number;
while( temp >= position)
{
array[temp+1] = array[temp];
temp --;
}

array[position] = element;
number = number +1 ;
return(number);
}

/* INPUT FUNCTION TO READ DATA */

void input(char array[], int number)
{
int i;
for(i = 1; i<= number ; i++)
{
fflush(stdin);
printf("\n Input value for: %d: ", i);
scanf("%c", &array[i]);
}
}

/* OUTPUT FUNCTION TO PRINT ON THE CONSOLE */

void display(char array[], int number)
{
int i;
for(i = 1; i<= number; i++)
{
printf("\n Value at the position: %d: %c ", i, array[i]);
}
}

/* main function */

void main()
{
int number;
char array[100];
int position;
char element;
fflush(stdin);
printf("\n Input the number of element into the LIST: ");
scanf("%d", &number);
fflush(stdin);
input(array, number);
printf("\n Entered list as follows:\n");
fflush(stdin);
display(array,number);
fflush(stdin);
printf("\n Input the position where you want add a new data:");
scanf("%d", &position);
fflush(stdin);
printf("\n Input the value for the position:");
scanf("%c", &element);
number = insert_array(array,number,position,element);
display(array,number);
}

Traversing a linear array.


void memory(int *, int, int);
void memory1(char *, int, int);

/* Definition of the function memory */

void memory(int a[], int l_b, int u_b)
{
int counter;

for(counter = l_b; counter<=u_b; counter++)
{
printf("\n Element at location: 0x%x is %d", &a[counter], a[counter]);
}
printf("\n Array size = %d ", &a[counter-1] - &a[0] + 1);
}

void memory1(char b[], int l_b, int u_b)
{
char *pointer;
int counter;
pointer =&b[0];

for(counter = l_b; counter<=u_b; counter++)
{
printf("\n Element at location: 0x%x is %d", &b[counter], b[counter]);
}
printf("\n Array size = %d", &b[counter-1] - &b[0] + 1);
}

/*Function main */

void main()
{
int a[12] = {99,88,77,66,55,44,33,22,11,100,200,300};
char b[] = {'A','B','C','D','E','F','G','H','I','J','K',
'L','M','N','O','P','Q','R','S','T','U','V',
'W','X','Y','Z' };
int lb=0, ub=11;
memory(a,lb,ub);
lb = 0;
ub = 25;
memory1(b,lb,ub);
}

Deleting Duplicate from a linear array.

int status ;
int dup;
int duplicate_array(int *, int);
void input(int *, int );
void display(int *, int );

/* Definition of the function */

int duplicate_array(int array[], int number)
{
int i, j, k;
status = 0;
dup = number;

for(i = 0; i< number-1; i++)
for(j = i+1; j< number; j++)
{
if(array[i] == array[j])
{
number = number - 1 ;
for(k = j; k
array[k] = array[k+1];
status = 1;
j = j - 1;
}
}
if( status ==0)
printf("\n No duplicate is found");
return(dup-number);
}

/* Input function to read data */

void input(int array[], int number)
{
int i;
for(i = 0; i< number ; i++)
{
printf("Input value for: %d: ", i+1);
scanf("%d", &array[i]);
}
}

/* Output function */

void display(int array[], int number)
{
int i;
for(i = 0; i< number; i++)
{
printf("\n Value at the position: %d: %d", i+1, array[i]);
}
}

/* main function */

void main()
{
int number;
int array[100];
int n;
printf("\n Input the number of elements in the list: ");
scanf("%d", &number);
input(array, number);
printf("\n Entered list is as follows:\n");

display(array,number);

n = duplicate_array(array,number);
printf("\nNumber of duplicate elements in the list are: %d", n);
printf("\nAfter removing duplicates from the list, the list is as follows:");
display(array,number-n);

Find a Inverse of a Matrix.


int i, j;

void display( int, int, float mat[10][10],float mat1[10][10]);
void input( int, int, float mat[10][10],float mat1[10][10]);
Inverse_Mat(int , int, float mat[10][10],float mat1[10][10]);
void swap(int, int, int, float mat[10][10],float mat1[10][10]);

/* This function exchange two rows of a matrix */

void swap( int row1,int row2, int col, float mat[10][10],float mat1[10][10])
{
for( i = 0; i < col; i++)
{
float temp = mat[row1][i];
mat[row1][i] = mat[row2][i];
mat[row2][i] = temp;

temp = mat1[row1][i];
mat1[row1][i] = mat1[row2][i];
mat1[row2][i] = temp;

}
}

/* This function find inverse of matrix */

int Inverse_Mat(int row1, int col1, float mat[10][10],float mat1[10][10])
{
int singular = 0;
int r, c;
for(r = 0;( r < row1)&& !singular; r++)
{

if( mat[r][r] ) /* Diagonal element is not zero */
for(c = 0; c < col1; c++)

if( c == r)
{

/* Make all the elements above and below the current principal
diagonal element zero */

float ratio = mat[r][r];
for( i = 0; i < col1; i++)
{
mat[r][i] /= ratio ;
mat1[r][i] /= ratio;
}
}
else
{
float ratio = mat[c][r] / mat[r][r];
for( i = 0; i < col1; i++)
{
mat[c][i] -= ratio * mat[r][i];
mat1[c][i] -= ratio * mat1[r][i];
}
}

else
{
/* If principal diagonal element is zero */
singular = 1;

for(c = (r+1); (c < col1) && singular; ++c)

if(mat[c][r])
{
singular = 0;
/* Find non zero elements in the same column */
swap(r,c,col1, mat, mat1);
--r;
}

}
}
return(!singular);
}

/* To print output this is used */

void display( int row, int col, float mat[10][10],float mat1[10][10])
{
printf("\n");
/* Output of inverse Matrix */
for( i = 0; i < row; i++)
{
for( j = 0; j < col; j++)
{
printf(" %f", mat1[i][j]);
}
printf("\n");
}

}

/* input function */

void input( int row, int col, float mat[10][10],float mat1[10][10])
{
for( i = 0 ; i< row; i++)
{
for( j = 0 ; j
{
printf("Input Value for: %d: %d: ", i+1, j+1);
scanf("%f", &mat[i][j]);
mat1[i][j] = 0;
}
mat1[i][i] = 1;
}
printf("\n Entered Matrix is as follows:\n");
for( i = 0; i < row; i++)
{
for( j = 0; j < col; j++)
{
printf(" %f", mat[i][j]);
}
printf("\n");
}
}


/* main function */


void main()
{

int R, C;
float mat[10][10];
float mat1[10][10];
printf("\n Input number of rows:");
scanf("%d", &R);
printf(" Input number of cols:");
scanf("%d", &C);
input(R,C, mat, mat1);

Inverse_Mat(R,C, mat, mat1);
printf("\n Inverse of above matrix is as follows:\n ");
display(R,C, mat, mat1);

Matrix Multiplication in C


# define row 10
# define col 10

int i, j;
int row1, col1;
int row2, col2;
float mat1[row][col];
float mat2[row][col];
float mat_res[row][col];

void mat_mult( float mat1[row][col], int, int,
float mat2[row][col], int, int,
float mat_res[row][col]);

void display(float mat[row][col], int, int);
void input(float mat[row][col], int , int);

/* function to multiply two matrices */

void mat_mult( float mat1[row][col], int row1, int col1,
float mat2[row][col], int row2, int col2,
float mat_res[row][col])
{
int i, j, k;
if(col1 == row2)
{
printf("\n Multiplication is possible and Result is as follows\n");

for(i =0; i< col1; k ++) { mat_res[i][j] += mat1[i][k] * mat2[k][j]; } } display(mat_res, row1, col2); } else printf("\n Multiplication is not possible"); exit(0); } /* Output function */ void display(float mat[row][col], int r, int c ) { for( i = 0; i < r; i++) { for( j = 0; j < c; j++) { printf(" %f", mat[i][j]); } printf("\n"); } } /* Input function */ void input(float mat[row][col], int r, int c) { for( i = 0 ; i< r; i++) { for( j = 0 ; j1:"); scanf("%d", &row1); printf("\n Input the col of the matrix->1:");
scanf("%d", &col1);

printf("\n Input data for matrix-> 1\n");
input(mat1, row1, col1);

printf("\n Input the row of the matrix ->2:");
scanf("%d", &row2);

printf("\n Input the col of the matrix->2:");
scanf("%d", &col2);

printf("\n Input data for matrix-> 2\n");
input(mat2, row2, col2);

printf("\n Entered Matrix First is as follows:\n");
display(mat1,row1,col1);

printf("\n Entered Matrix Two is as follows:\n");
display(mat2,row2,col2);

mat_mult(mat1 ,row1 ,col1, mat2, row2, col2, mat_res);
}

Find a Rank of Matrix.

int R,C;
int i, j;
int mat[10][10];

void display( int, int);
void input( int, int);
int Rank_Mat(int , int);
void swap(int, int, int);

/* This function exchange two rows of a matrix */

void swap( int row1,int row2, int col)
{
for( i = 0; i < col; i++)
{
int temp = mat[row1][i];
mat[row1][i] = mat[row2][i];
mat[row2][i] = temp;
}
}

/* This function find rank of matrix */

int Rank_Mat(int row1, int col1)
{
int r, c;
for(r = 0; r< col1; r++)
{
display(R,C);
if( mat[r][r] ) // Diagonal element is not zero
for(c = 0; c < row1; c++)
if(c != r)
{
/* Make all the elements above and below the current principal
diagonal element zero */

float ratio = mat[c][r]/ mat[r][r];
for( i = 0; i < col1; i++)
mat[c][i] -= ratio * mat[r][i];
}

else
printf("\n");

/* Principal Diagonal elment is zero */

else
{
for(c = r+1 ; c < row1; c++)
if (mat[c][r])
{
/* Find non zero elements in the same column */
swap(r,c,col1);
break ;
}

if(c == row1)
{
-- col1;

for(c = 0; c < row1; c ++)
mat[c][r] = mat[c][col1];
}
--r;
}
}
return col1;
}

/* Output function */

void display( int row, int col)
{
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
printf(" %d", mat[i][j]);
}
printf("\n");
}
}

/* Input function */

void input( int row, int col)
{
int value;
for(i = 0 ; i< row; i++)
{
for(j = 0 ; j
{
printf("Input Value for: %d: %d: ", i+1, j+1);
scanf("%d", &value);
mat[i][j] = value;
}
}
}

/* main function */

void main()
{
int rank;
printf("\n Input number of rows:");
scanf("%d", &R);
printf("\n Input number of cols:");
scanf("%d", &C);
input(R, C);
printf("\n Row is : %d", R);
printf("\n Column is : %d \n", C);

printf("\n Entered Two Dimensional array is as follows:\n");
display(R,C);
printf("\n Row is : %d", R);
printf("\n Column is : %d\n", C);

rank = Rank_Mat(R, C);
printf("\n Rank of above matrix is : %d", rank);
}