View Code of Problem 61

#include<string.h>
#include<stdio.h>
#include<math.h>
int main(){
	int i,n,j,k;
	int t;
	int len;
	int a[1000];

	scanf("%d",&t);
	while(t--){
		int temp;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(k=0;k<n-1;k++){
			for(j=k+1;j<n;j++){
				if(a[k]>a[j]){
					temp=a[j];
					a[j]=a[k];
					a[k]=temp;
				}
			}
		}
		int max=0;
		int p;
		for(j=n,p=1;j>0,p<=n;j--,p++){
			b[j]=a[j]*(p-1);
		
			if(b[j]>max){
				max=b[j];
			}
		}
		printf("%d",max);
		
	}
	
	return 0;
}
/*
Main.c: In function 'main':
Main.c:28:18: warning: left-hand operand of comma expression has no effect [-Wunused-value]
   for(j=n,p=1;j>0,p<=n;j--,p++){
                  ^
Main.c:29:4: error: 'b' undeclared (first use in this function)
    b[j]=a[j]*(p-1);
    ^
Main.c:29:4: note: each undeclared identifier is reported only once for each function it appears in
Main.c:7:6: warning: unused variable 'len' [-Wunused-variable]
  int len;
      ^~~
*/

Double click to view unformatted code.


Back to problem 61