[ create a new paste ] login | about

Link: http://codepad.org/Jua2dneG    [ raw code | output | fork ]

C++, pasted on Dec 25:
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

const int m = 5;
const int n = 10;

int main(int argc, char* argv[])
{
	int** A = new int*[m];
	memset((void*)A, 0x00, 4 * m);

	for (int z1 = 0; z1 < m; z1++)
	{
		A[z1] = new int[n];
		for (int z2 = 0; z2 < n; z2++)
		{
			A[z1][z2] = rand() % 9 + 1;
			printf("%d ",A[z1][z2]);
		}

		printf("\n");
	}

	int max = 0, max_i = 0;
	for (int i = 0; i < m; i++)
	{
		int sum = 0, j = 0;
		while (j < n) sum+=A[i][j++];
		if (sum > max) { max = sum; max_i = i; }
	}

	printf("\nsum = %d row = %d\n",max,max_i);

	return 0;
}


Output:
1
2
3
4
5
6
7
2 8 1 8 6 8 2 4 7 2 
6 5 6 8 6 5 7 1 8 2 
9 9 7 7 9 9 9 5 2 2 
6 1 1 4 6 4 2 8 5 8 
7 1 1 3 6 5 6 3 3 4 

sum = 68 row = 2


Create a new paste based on this one


Comments: