Created
November 29, 2012 17:02
-
-
Save CaglarGonul/4170405 to your computer and use it in GitHub Desktop.
Matrix Summation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
void CreateMatrixBySize(int*,int,int); | |
void PrintMatrixBySize(int*,int,int); | |
void MatrixSummationFunction(int*,int*,int*,int,int); | |
int main(int argc, char *argv[]) { | |
int xSize, ySize; | |
printf("Toplama icin matrix X boyutunu belirleyin: "); | |
scanf("%d", &xSize); | |
printf("Toplama icin matrix Y boyutunu belirleyin: "); | |
scanf("%d", &ySize); | |
int A[xSize][ySize], B[xSize][ySize], C[xSize][ySize]; | |
printf("A matrixi icin degerleri girin : \n"); | |
CreateMatrixBySize(&A[0][0],xSize,ySize); | |
printf("B matrixi icin degerleri girin : \n"); | |
CreateMatrixBySize(&B[0][0],xSize,ySize); | |
MatrixSummationFunction(&A[0][0],&B[0][0],&C[0][0],xSize,ySize); | |
PrintMatrixBySize(&A[0][0],xSize,ySize); | |
printf("+\n"); | |
PrintMatrixBySize(&B[0][0],xSize,ySize); | |
printf("=\n"); | |
PrintMatrixBySize(&C[0][0],xSize,ySize); | |
int s; | |
printf("Programi sonlandirmak icin bir karakter giriniz : "); | |
scanf("%d",&s); | |
return 0; | |
} | |
void CreateMatrixBySize(int* matrixToBeCreated,int dimX ,int dimY){ | |
int i,j; | |
for(i=0;i<dimX;i++){ | |
for(j=0;j<dimX;j++){ | |
printf("(%d,%d) :",i,j); | |
scanf("%d",&matrixToBeCreated[i*dimY+j]); | |
} | |
} | |
} | |
void PrintMatrixBySize(int* matrixToBePrinted, int dimX ,int dimY){ | |
int i,j; | |
for(i=0;i<dimX;i++){ | |
printf("["); | |
for(j=0;j<dimY;j++){ | |
printf("%4d%4s",matrixToBePrinted[i*dimY+j],""); | |
} | |
printf("]\n"); | |
} | |
} | |
void MatrixSummationFunction(int *matrixA,int* matrixB, int*matrixC,int dimX, int dimY){ | |
int i,j; | |
for(i=0;i<dimX;i++){ | |
for(j=0;j<dimY;j++){ | |
matrixC[i*dimY+j]= matrixA[i*dimY+j] + matrixB[i*dimY+j]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment