#include "stdio.h"
#include "conio.h"
#include "alloc.h"
#define TRUE 1
#define FALSE 0
void main()
{
int *a1,*a2,*a3,i,j,size=0,repeated,num;
clrscr();
printf("How Many Numbers? ");
scanf("%d",&num);
a1=(int *) malloc(num*sizeof(int));
a2=(int *) malloc(num*sizeof(int));
a3=(int *) malloc(num*sizeof(int));
printf("\nEnter %d Numbers:\n",num);
for(i=0;i
scanf("%d",&a1[i]);
/* Copying the elements of array a1 to another array a2 */
a2[i]=a1[i];
repeated=FALSE;
for(j=0;j
if(a1[i]==a2[j])
{
repeated=TRUE;
break;
}
if(!repeated)
a3[size++]=a1[i];
}
printf("\nRepeated Numbers Excluded.");
printf("\nPrinting Third Array...\n");
for(i=0;i
free(a1);
free(a2);
free(a3);
getch();
}
Friday, June 26, 2009
PROGRAM TO EXCLUDE THE REPEATED ELEMENTS FROM AN ARRAY
Labels: Arrays, Loops, Nice Programs
Posted by Unknown at 12:48 AM 0 comments
PROGRAM TO PRINT THE TRANSPOSE OF MATRIX
#include "stdio.h"
#include "conio.h"
#define ROW 5
#define COL 4
void main()
{
int a[ROW][COL],i,j;
clrscr();
printf("Enter 5*4 Matrix:\n");
for(i=0;i
/* Transpose of Matrix can simply be printed */
/* by changing Rows and Columns */
printf("\n");
printf("Transpose of Matrix:\n");
for(j=0;j
for(i=0;i
printf("\n");
}
getch();
}
Posted by Unknown at 12:47 AM 0 comments
PROGRAM TO SORT 2 ARRAYS AND MERGE THEM INTO A SINGLE ARRAY
#include "stdio.h"
#include "conio.h"
#include "alloc.h"
void main()
{
int *a,*b,*c,i,j,m,n,temp;
clrscr();
printf("How many elements are there in array first? ");
scanf("%d",&m);
a=(int *)malloc(m*sizeof(int));
printf("\nEnter The Elements of Array first:\n");
for(i=0;i
printf("\nHow many elements are there in array Second? ");
scanf("%d",&n);
b=(int *)malloc(n*sizeof(int));
printf("\nEnter The Elements of Array Second:\n");
for(i=0;i
printf("\nSorting Both Arrays...\n");
for(i=0;i
if(a[j] {
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
for(i=0;i
if(b[j] {
temp=b[j];
b[j]=b[j-1];
b[j-1]=temp;
}
c=(int *)malloc((m+n)*sizeof(int));
printf("\nCopying First array to Third array....\n");
for(i=0;i
printf("\nCopying Second array to Third array...\n");
for(i=m,j=0;i<(m+n);i++,j++)
c[i]=b[j];
printf("\nNow Printing Third array...\n");
for(i=0;i<(m+n);i++)
printf("%d\t",c[i]);
free(a);
free(b);
free(c);
getch();
}
Posted by Unknown at 12:46 AM 0 comments