click on this link......

LinkGrand.com

Friday 6 December 2013

Pascal triangle


   1

  1 1

 1 2 1

1 3 3 1

Pascal triangle in c

#include <stdio.h>
 
long factorial(int);

 

int main()

{

   int i, n, c;

 

   printf("Enter the number of rows you wish to see in pascal triangle\n");

   scanf("%d",&n);

 

   for ( i = 0 ; i < n ; i++ )

   {

      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )

         printf(" ");

 

      for( c = 0 ; c <= i ; c++ )

         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));

 

      printf("\n");

   }

 

   return 0;

}

 

long factorial(int n)

{

   int c;

   long result = 1;

 

   for( c = 1 ; c <= n ; c++ )

         result = result*c;

 

   return ( result );

}

Program to find Transpose of a matrix


This c program prints transpose of a matrix. It is obtained by interchanging rows and columns of a matrix. For example if a matrix is
1 2
3 4
5 6
then transpose of above matrix will be
1 3 5
2 4 6
When we transpose a matrix then the order of matrix changes, but for a square matrix order remains same.

C programming code

#include <stdio.h>
#include <conio.h>

 

void main()

{

   int row, col, i, j, matrix[10][10], transpose[10][10];

 

   printf("Enter the number of rows and columns of matrix ");

   scanf("%d%d",&row,&col);

   printf("Enter the elements of matrix \n");

 

   for( i = 0 ; i < row ; i++ )

   {

      for( j = 0 ; j < col ; j++ )

      {

         scanf("%d",&matrix[i][j]);

      }

   }

 

   for( i = 0 ; i < row ; i++ )

   {

      for( j = 0 ; j < col ; j++ )

      {

         transpose[j][i] = matrix[i][j];

      }

   }

 

   printf("Transpose of entered matrix :-\n");

 

   for( i = 0 ; i < col ; i++ )

   {

      for( j = 0 ; j < row ; j++ )

      {

         printf("%d\t",transpose[i][j]);

      } 

      printf("\n");

   }

 

   getch();

}