Wednesday, November 9, 2011

Matrix Insertion, Display, Addition, Subtraction and Multiplication



#include

int main(void)
{
        int a[3][3],b[3][3],c[3][3];
        int i,j;
        printf("\a \a \a \a enter element of first matrix\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("\nenter a[%d][%d] element=",i,j);
                        scanf("%d",&a[i][j]);
                }
        }
        printf("\nenter element of second matrix");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("\nenter b[%d][%d] element=",i,j);
                        scanf("%d",&b[i][j]);
                }
        }
        printf("\n\nmatrix a is....\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("%d\t",a[i][j]);
                }
                printf("\n");
        }
        printf("content of matrix b is=\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("%d\t",b[i][j]);
                }
                printf("\n");
        }
        printf("\n welcom to addition\n");
        for(i=0;i<3;i++)
  {
                for(j=0;j<3;j++)
                {
                        c[i][j]=a[i][j]+b[i][j];
                }
        }
        printf("\n\nmatrix after addition is \n=");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("%d\t",c[i][j]);
                }
                printf("\n");
        }
        printf("\n welcom to substraction\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        c[i][j]=a[i][j]-b[i][j];
                }
        }
        printf("\n\nmatrix after substraction is \n=");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("%d\t",c[i][j]);
                }
                printf("\n");
        }
        int k;
        printf("\n welcom to multiplication\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        for(k=0;k<3;k++)
                        {
                                c[i][j]=c[i][j]+a[i][k]*b[k][j];
                        }
                }
 }
        printf("\n\nmatrix after multi is \n=");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("%d\t",c[i][j]);
                }
                printf("\n");
        }
}

Monday, November 7, 2011

Array Intialization, Insertion, Sorting.. program...


//Proram to Intialize, Insertion and sorting in array....
#include

int main(void)
{
int mark[5];
int i;
printf("Enter the marks of student");
for(i=0;i<5;i++)
 {
  printf("Enter the marks of %d student",i);
  canf("%d",&mark[i]);
 }
 printf("\n marks submitted succesfully");
 printf("\n marks entered by you are");
 for(i=0;i<5;i++)
 {
  printf("\n marks of %d studentis= %d",i,mark[i]);
  printf("\t addres location is =%d", &mark[i]);
 }

 printf("\n----Welcome to search----");
 int num;
 printf("Enter number you want to search");
 scanf("%d",&num);
 for (i=0;i<5;i++)
 {
  if(num==mark[i])
  {
   printf("Element found at %d Location",i);
   printf("\t Address Location is=%d",&mark[i]);
   break;
  }
 }
 if(i==5)
 {
  printf("Oops--Element not found");
 }
 int temp;
 printf("~~~~~~WelCome To searching~~~~~~~");
 int j;
 for(j=0;j<5;j++)
 {
  for(i=0;i<4;i++)
  {
   if(mark[i] > mark[i+1])
{
temp=mark[i];
mark[i]=mark[i+1];
mark[i+1]=temp;
}
}

}
printf("Values after sorting are");
printf("\n");
for(i=0;i<5;i++)
{
printf("\n Element %d is=%d",i,mark[i]);
printf("\t Address is =%d",&mark[i]);
}
}