Write a program that calculates the sum of the upper triangular matrix.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
#define SIZE 50
void main()
{
	int A[SIZE][SIZE];
	int R, C;        /* dimensions */
	int I, J, sum=0;

	do {
		printf("Number of rows   (max.%d) : ", SIZE);
		scanf("%d", &R);
	} while (R <= 0 || R > SIZE);
	do {
		printf("Number of columns (max.%d) : ", SIZE);
		scanf("%d", &C);
	} while (C <= 0 || C > SIZE);

	printf("*** Matrix ***\n");
	for (I = 0; I<R; I++)
		for (J = 0; J<C; J++)
		{
			printf("A[%d][%d] : ", I, J);
			scanf("%d", &A[I][J]);
		}


	for (I = 0; I < R; I++)
		for (J = I+1; J < R; J++)
			sum+=A[I][J];


	printf("Sum = %d\n",sum);
	
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Boolean expression