All pastes #228252 Raw Edit

eCli

public text v1 · immutable
#228252 ·published 2006-10-29 23:33 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define DIMSIZE 5

void fillTriangularMatrixRandom(int A[][DIMSIZE]);
void display2DMatrix(int A[][DIMSIZE]);
void transformTriangular(int A[][DIMSIZE], int B[]);
void setValue(int i, int j, int val, int B[]);


main()
{
	int A[DIMSIZE][DIMSIZE];
	int B[DIMSIZE*(DIMSIZE+1)/2]; //yparxoyn N(N+1)/2 stoixeia poy briskontai 
								  //apo th diagonio kai kato
	//int index,value;
	srand(time(0));
	printf("PINAKAS A");
	fillTriangularMatrixRandom(A);
	printf("\nArxikopoihsh me random times oloklhrothike\n");
	printf("\nPINAKAS A\n");
	display2DMatrix(A);
	transformTriangular(A,B);

	return 0;

}

void fillTriangularMatrixRandom(int A[][DIMSIZE])
{
	int i,j;
	for(i=0; i<5; i++)
		for(j=0; j<5; j++)
			if(i>=j)
				A[i][j] = rand()%10;
			else A[i][j] = 0;
}

void display2DMatrix(int A[][DIMSIZE])
{
	int i,j;

	for(i=0; i<5; i++){
		for(j=0; j<5; j++)
			printf("%d ",A[i][j]);
		printf("\n");
	}
}

void transformTriangular(int A[][DIMSIZE], int B[])
{
	int i,j;

	for(i=0; i<5; i++)
		for(j=0; j<5; j++)
			if(i>=j)
				setValue(i,j,A[i][j],B);
			
}

void setValue(int i, int j, int val, int B[])
{
	
	i = 0;
	B[i] = val;
	i = i+1;
}