Powered By Blogger

Wednesday 27 April 2011

Different operations like Insertion,Deletion,Display,Linear Search,Binary Search,Bubble Sort,Selection Sort, Insertion Sort, Swapping performed on a user defined length restricted linear data structure(ARRAY) in C


#include<stdio.h>
void insert(int *);
void del(int *);
void display(int *);
void lsearch(int *);
void bsearch(int *);
void bsort(int *);
void ssort(int *);
void isort(int *);
void Swap(int *);
void insrt(int *,int,int);
int fmin(int *,int,int);
// GLOBAL VARIABLES USED TO KEEP TRACK OF THE ARRAY
int count=0,length=0,empty=0;

//Start of Main();
int main(void)
{
int *array;
int choice,i=0;
int elem=3;


Saddle point of a matrix in C


#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=0,j=0,k=0,r=0,c=0,max=0,min=0,col=0,row=0;
int **a;
printf("\nPlease enter the order of the first matrix::\n");
scanf("%d",&r);
printf("X\n");
scanf("%d",&c);
a=(int**)malloc(r*sizeof(int*));
for(i=0;i<r;i++)
{
a[i]=(int*)malloc(c*sizeof(int));
}
printf("\nEnter the element of the matrix::\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}

Matrix Minima method in C


#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=0,j=0,k=0,r=0,c=0,max=0,min=0,col=0,row=0;
int **a,flag=0,supply=0,demand=0,sum=0,temp=0,count=0,mr=0,mc=0;
printf("\n************* MATRIX MINIMA RULE *************\n");
printf("\nPlease enter the order of the first matrix:\n");
scanf("%d",&mr);
printf("X\n");
scanf("%d",&mc);
r=mr+1;
c=mc+1;
a=(int**)malloc(r*sizeof(int*));
for(i=0;i<r;i++)
{
a[i]=(int*)malloc(c*sizeof(int));
}
printf("\nEnter the element of the matrix:\n");
for(i=0;i<mr;i++)
{
for(j=0;j<mc;j++)
{
scanf("%d",&a[i][j]);
}
}

North West Corner Rule in C


#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=0,j=0,k=0,r=0,c=0,max=0,min=0,col=0,row=0;
int **a,flag=0,supply=0,demand=0,sum=0,temp=0,count=0,mr=0,mc=0;
printf("\n************* NORTH WEST CORNER RULE *************\n");
printf("\nPlease enter the order of the first matrix:\n");
scanf("%d",&mr);
printf("X\n");
scanf("%d",&mc);
r=mr+1;
c=mc+1;
a=(int**)malloc(r*sizeof(int*));
for(i=0;i<r;i++)
{
a[i]=(int*)malloc(c*sizeof(int));
}
printf("\nEnter the element of the matrix:\n");
for(i=0;i<mr;i++)
{
for(j=0;j<mc;j++)
{
scanf("%d",&a[i][j]);
}
}

Implementation of Jacobi rule using C


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
int dominat(float**);
float compute(float**,float,float,int);
int main(void)
{
float **arr,*x,*y,*z,e=0.001;
int i=0,j=0,dom,c=0;

//Dynamic allocation
x=(float*)malloc(1000*sizeof(float));
y=(float*)malloc(1000*sizeof(float));
z=(float*)malloc(1000*sizeof(float));
arr=(float**)malloc(3*sizeof(float*));
for(i=0;i<3;i++)
arr[i]=(float*)malloc(4*sizeof(float));
//Allocation complete


Gauss Seidel method using C


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
int dominat(float**);
float compute(float**,float,float,int);
int main(void)
{
float **arr,*x,*y,*z,e=0.001;
int i=0,j=0,dom,c=0;

//Dynamic allocation
x=(float*)malloc(1000*sizeof(float));
y=(float*)malloc(1000*sizeof(float));
z=(float*)malloc(1000*sizeof(float));
arr=(float**)malloc(3*sizeof(float*));
for(i=0;i<3;i++)
arr[i]=(float*)malloc(4*sizeof(float));
//Allocation complete


Addition of a digit to the elements of an array using pointer arithmetic, while the user defined array is passed to the called function using pointer.


#include<stdio.h>
void pass(int *);
int main(void)
{
int *array,i=0,*a;
int b=10;
array=(int*)calloc(sizeof(int)*b);
printf("Enter the %d elements of the array :: ",b);
for(i=0;i<10;i++)
{
scanf(" %d",&array[i]);
}
a=array;
pass(a);
for(i=0;i<10;i++)
{
printf("%d ",array[i]);
}
return 0;
}

A simple program to pass a string to another function using pointer and to print it from called function.


#include<stdio.h>
void pass(char *);

int main(void)
{
char *string="Subhabrata";
pass(string);
return 0;
}

void pass(char *pass)
{
int i=0;
char *t=pass;
t=pass;
for(i=0;i<10;i++)
{
printf("%c",*t++);
}
}

This C programme will split one Source txt file into two equally sized text file

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main(void)
{
int enter=0,lines=0,count=0,flag=0;
int i=0,condition=0;
char temp='\n';
FILE *fp1;
FILE *fp2;
FILE *fp3;
fp1=fopen("exsisting.txt","a+");
fp2=fopen("splitted1.txt","w+");
fp3=fopen("splitted2.txt","w+");

i=0;