Thursday, April 3, 2014

PROGRAM TO PRINT THE FREQUENCY OF EACH ELEMENT IN AN ARRAY

//PROGRAM TO PRINT THE FREQUENCY OF EACH ELEMENT IN AN ARRAY

#include<conio.h>
#include<stdio.h>
void main()
{
int a[10],i,c,j,n;
clrscr();
printf("enter the limit of array\n");
scanf("%d",&n);
printf("enetr the elements of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
c=0;
for(j=0;j<n;j++)
{
if(a[i]==a[j])
{
c++;
}
}
printf("the frequency of element %d at %d index is %d\n",a[i],i,c);
}
getch();
}

PROGRAM TO PRINT THE LOWER TRIANGLE OF A MATRIX

//PROGRAM TO PRINT THE LOWER TRIANGLE OF A MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,n;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
if(row==col)
{
printf("the lower triangular matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(j<i||j==i)
{
printf(" %d ",ar[i][j]);
}
}
printf("\n\n");
}
}
else
printf("cant calculate the lower matrix");
getch();
}

PROGRAM TO PRINT THE UPPER TRIANGLE IN A MATRIX

//PROGRAM TO PRINT THE UPPER TRIANGLE IN A MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,n;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
if(row==col)
{
printf("the upper triangular matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(j>i||j==i)
{
printf(" %d ",ar[i][j]);
}
else
{
printf("   ");
}
}
printf("\n\n");
}
}
else
printf("cant calculate th e upper matrix");
getch();
}

PROGRAM FOR SUM OF ROW AND COLUMN OF NON SQUARE/SQUARE MATRIX

//PROGRAM FOR SUM OF ROW AND COLUMN OF NON SQUARE/SQUARE MATRIX

#include<stdio.h>
#include<conio.h>
main()
{
 int i,j,k,A[10][10],R_S,C_S,r,c;
 clrscr();
 printf(" ENTER THE SIZE OF A MATRIX \n");
 scanf("%d%d",&r,&c);

 printf("ENTER THE ELEMENT OF A MATRIX \n");
 for(i=0;i<r;i++)
  for(j=0;j<c;j++)
    scanf("%d",&A[i][j]);

 /* Sum of rows */
 for(i=0;i<r;i++)
 {
   R_S=0;
    for(j=0;j<c;j++)
        {
        R_S=R_S+A[i][j];
}
printf("\nSum of %d row is %d",i+1,R_S);
 }

/* Sum of Column */
for(i=0;i<c;i++)
{
        C_S=0;
          for(j=0;j<r;j++)
   {
    C_S=C_S+A[j][i];
           }
   printf("\nSum of %d Col is %d",i+1,C_S);
}

getch();
  }

PROGRAM TO PRINT THE ROW SUM,COLUMN SUM AND DIAGONAL SUM OF A SQUARE MATRIX

//PROGRAM TO PRINT THE ROW SUM,COLUMN SUM AND DIAGONAL SUM OF A SQUARE MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,r_s,c_s,d_s=0;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
for(i=0;i<row;i++)
{
r_s=0;c_s=0;
for(j=0;j<col;j++)
{
r_s=r_s+ar[i][j];
c_s=c_s+ar[j][i];
if(i==j)
{
d_s=d_s+ar[i][j];
}
}
printf("\nsum of row %d is %d",i,r_s);
printf("\nsum of col %d is %d",i,c_s);
}
printf("\nsum of diagonal is %d",d_s);
getch();
}

PROGRAM TO PRINT THE TRANSPOSE OF A MATRICES

PROGRAM TO PRINT THE TRANSPOSE OF A MATRICES

#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],i,j,r,c;
clrscr();
printf("enter the no of rows\n");
scanf("%d",&r);
printf("enter the no of col\n");
scanf("%d",&c);
printf("enter the matrics\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("the elements of matrics\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}
printf("the transpose of matrics is\n");
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
printf(" %d ",a[j][i]);
printf("\n\n");
}
getch();
}

PROGRAM TO MULTIPLY TWO MATRICES

//PROGRAM TO MULTIPLY TWO MATRICES
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],k,i,j,r1,c1,r2,c2;
clrscr();
printf("enetr the no of rows of first matrics\n");
scanf("%d",&r1);
printf("enter the no of cols of first matrics\n");
scanf("%d",&c1);
printf("enetr the no of rows of second matrics\n");
scanf("%d",&r2);
printf("enter the no of cols of second matrics\n");
scanf("%d",&c2);
printf("enter the elements of first matrics\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}
printf("the elements of first matrics are \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}
printf("enter the elements of second matrics\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}
printf("the elements of second matrics are \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf(" %d ",b[i][j]);
printf("\n\n");
}

if(c1==r2)
{
printf("the multiplication of two matrices is\n");
for(i=0;i<r1;i++)
{
 for(j=0;j<c2;j++)
   {
     c[i][j]=0;
      for(k=0;k<c1;k++)
       {
        c[i][j]=c[i][j]+a[i][k]*b[k][j];
       }
     printf(" %d ",c[i][j]);
   }
  printf("\n\n");
}
}
else
printf("multiplication is not possible\n");

getch();
}