View Code of Problem 65

#include<stdio.h>

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int r;
		scanf("%d",&r);
		int a[r][r]={0};
		for(int i=1;i<=r;i++){
			for(int j=1;j<=i;j++){
				scanf("%d",&a[i][j]);
			}
		}
		for(int i=r-1;i>=1;i--){
			for(int j=1;j<=i+1;j++){
				if(a[i+1][j]>a[i+1][j+1])
					a[i][j]+=a[i+1][j];
				else
					a[i][j]+=a[i+1][j+1];
			}
		}
		printf("%d\n",a[1][1]);
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:9:3: error: variable-sized object may not be initialized
   int a[r][r]={0};
   ^~~
Main.c:9:16: warning: excess elements in array initializer
   int a[r][r]={0};
                ^
Main.c:9:16: note: (near initialization for 'a[0]')
Main.c:9:3: warning: excess elements in array initializer
   int a[r][r]={0};
   ^~~
Main.c:9:3: note: (near initialization for 'a')
*/

Double click to view unformatted code.


Back to problem 65