Showing posts with label Matrices. Show all posts
Showing posts with label Matrices. Show all posts

Tuesday, 5 September 2017

C-Program to print sum of Columns in matrix using GOTO Statement



#include<stdio.h>

int main()
{
 int i,j,rows,col,sum_rows,sum_col,k=0;
 printf("Enter number of rows and columns of a matrix\n");
 scanf("%d %d",&rows,&col);
int a[rows][col];

  //Taking input of matrix
    printf("Enter Matrix 1\n");
    for(i=0;i<rows;i++)
    {
       for(j=0;j<col;j++)
      {
     scanf("%d",&a[i][j]);
      }
    }
   
    printf("Given /matrix is\n");
        for(i=0;i<rows;i++)
         {
         for(j=0;j<col;j++)
         {
           printf("%d\t",a[i][j]);
           }
 
           printf("\n");
           }
  k=0;
  i=0;
   FirstLoop:
   {
        if(i<col)
      {
          sum_col=0;
          j=0;
          SecondLoop:
          {
           if(j<rows)
           {
            sum_col+=a[j][i];
            j++;
            goto SecondLoop;
            }
          }
            printf("Sum of %d Column is %d\n",k,sum_col);
            k++;
            i++;
            goto FirstLoop;
         }
  }   
return 0;
}

C-Program to Check whether given Matrix is Orthogonal or not



#include<stdio.h>

int main()
{
 int i,j,k,size,flag=1;
 printf("Enter size of square matrix i.e 3 for 3x3 and 4 for 4x4 etc\n");
 scanf("%d",&size);
 int a[size][size],temp[size][size],identityCheck[size][size],sum=0;
 printf("Enter Elements in matrix\n");
 for(i=0;i<size;i++)
 {
  for(j=0;j<size;j++)
  {
   scanf("%d",&a[i][j]);
  }
 }
 //Transpose of given matrix
 for(i=0;i<size;i++)
 {
  for(j=0;j<size;j++)
  {
   temp[i][j]=a[j][i];
  }
 }

 //Multiplying given A with A^T
 for(i=0;i<size;i++)
 {
  for(j=0;j<size;j++)
  {
   for(k=0;k<size;k++)
   {
    sum+=(a[i][k]*temp[k][j]);
   }
   identityCheck[i][j]=sum;
   sum=0;
  }
 }

 //Checking whether A*A^T resulted in Identity Matrix or not

 for(i=0;i<size;i++)
 {
  for(j=0;j<size;j++)
  {
   if(i==j && identityCheck[i][j]!=1)
   flag=0;
   if(i!=j && identityCheck[i][j]!=0)
   flag=0;
  }
 }

 //Checking for Orthogonal Matrix or not
 if(flag==1)
 {
  printf("Given Matrix is Orthogonal Matrix\n");
 }
 else
 {
  printf("Given Matrix is not an Orthogonal Matrix\n");
 }
return 0;
}