Posts

Showing posts with the label Array

Multiplication of Matrix

Image
                                                                                 Multiplication of Matrix C program to multiplication of matrix :-  #include <stdio.h> #include <conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j,k; clrscr(); printf("\n\t Enter First Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Enter Second Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k...

Subtraction of matrix

Image
                                             Subtraction of matrix Subtraction of matrix means that one matrix is subtracted for another and result is putted into third matrix. C program to subtract matrix:-   #include <stdio.h> #include <conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j,k; clrscr(); printf("\n\t Enter First Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Enter Second Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } printf("\n\t Matrix Multiplication is : \n\n"); for(i=...

Addition of matrix

Image
                                        Addition of matrix   Addition of matrix means that two matrix are added and addition of both matrix is putted in into third matrix. C program to add matrix:-   #include <stdio.h> #include <conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("\n\t Enter First Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Enter Second Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf("\n\t Matrix Addition is : \n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t %d",c[i][j]); } printf("\n"); } ge...

Magic square matrix

Image
                                                                           Magic square matrix A magic square is a square array of  numbers consisting  of  the distinct positive integer ,arranged such that the sum of the numbers in any horizontal,vertical or main diagonal line is always the same number C program of Magic square matrix :-  void main() { int n, i, j, c, a[9][9] ; clrscr() ; printf("Enter the size of the magic square : ") ; scanf("%d", &n) ; if (n % 2 == 0) { printf("\nMagic square is not possible") ; goto end ; } printf("\nThe magic square for %d x %d is :\n\n", n, n) ; j = (n ...

Transpose of matrix

Image
                                                 Transpose of matrix The transpose of a matrix A is a matrix formed formed from A by interchanging the rows  and columns such that row i of a matrix  A becomes column i of the transposed matrix.The transpose of A is denoted by AT.Each element a a q in A becomes element a p in AT.If A is a m by n matrix ,then AT is an n and m matrix .The  following represents a matrix and its transpose. C program to transpose matix:-  #include <stdio.h> #include <conio.h> void main() { int a[3][3],i,j; clrscr(); printf("\n\t Enter Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Transpose of Matrix is : \n\...

Square matrix

Image
                                                             Square matrix     The square matrix is 2D-Array or matrix in which both number of  rows and columns are equal. Example 1:-     int list[5][5]; X = main diagonal -  = upper triangular + = lower triangular Example 2 :- int list[5][5]; main diagonal     = 2,5,5,8,7 upper triangular  = 3,5,8,4,7,9,8,2,3,2 lower triangular  = 2,8,3,3,5,3,7,1,2,5

2d array in c language

Image
                                          2D array in C# language The array which is used to represent and store data in a tabular form is called as 'two dimensional array.' Such type of array specially used to represent data in a matrix form. Syntax:-  <data type><array name>[No of rows][No of columns] int a[3][3]; Initialization of 2D Array:- <data type><array name>[No of rows][No of columns] int list[3][5]={{1,2,3,4,5}{6,7,8,9,10}{11,12,13,14,15}}; Memory Allocation :                                                       Column          ...

C# program to sum members of array

           C# program to sum members of Array /*website: http://ankitcguru.blogspot.com/ *programmer:ankit gehlot*/ #include<stdio.h> #include<conio.h> void main() { int sum=0,i; int num[10]; for(i=0;i<10;i++){ printf("enter value in array:"); scanf("%d",&num[i]); sum=sum+num[i]; } printf("sum of array:%d",sum); getch(); } Output:-   enter value in array:1 enter value in array:2 enter value in array:3 enter value in array:4 enter value in array:5 enter value in array:6 enter value in array:7 enter value in array:8 enter value in array:9 enter value in array:10 sum of array:55

Array

                                                                        Array        Array is a collection of similar data type element which have save name but distinguish from index number. C# arrays are zero indexed; that is, the array indexes start at zero. Arrays in C# work similarly to how arrays work in most other popular languages There are, however, a few differences that you should be aware of.( reference ) Syntax:-   int salary [100]; data array name size Initialization:-  int num [5]={1,5};//or int num2[5]; num2[0]=13; num2[1]=14; num2[2]=15; num2[3]=16; With index address it looks like shown below:- address array value 65520 num2[0] 13 65522 num2[1] 14 65524 num2[2] 15 65526 num2[...

Matrix multiplication in c

#include <stdio.h>   int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10];   printf("Enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix\n");   for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) scanf("%d", &first[c][d]);   printf("Enter the number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q);   if ( n != p ) printf("Matrices with entered orders can't be multiplied with each other.\n"); else { printf("Enter the elements of second matrix\n");   for ( c = 0 ; c < p ; c++ ) for ( d = 0 ; d < q ; d++ ) scanf("%d", &second[c][d]);   for ( c = 0 ; c < m ; c++ ) { for ( d = 0 ; d < q ; d++ ) { for ( k = 0 ; k < p ; k++ ) ...