Maximum

In your code d is the total number of elements. You are reading only 3 integers in

this statement. You should read total d numbers.

1 Like

Input will contain more than four value.
And you don’t need to print All are equal

1 Like

@hjr265
N = int(input(“”))
a = []

for i in range(0, N):
a.append(int(input(“”)))

print(max(a))

What is the problem in this code?

what is the problem?

N = int(input(“”))
Max = 0
arr = {}

for i in range(0, N):
arr[i] = int(input(“”))
if arr[i] > Max:
Max = arr[i]

print(Max)

#include <stdio.h>
int main(){
int N,i,A[i],max=0;
scanf(“%d”,&N);
for(i=0;i<N;i++){
scanf(“%d”,&A[i]);
if(A[i]>max){max=A[i];}
}
printf(“%d”,max);
return 0;
}

what’s wrong with this code?(C)
it’s getting wrong in 2nd case

@omar24, your way of taking inputs is not right.
Try this to store multiple numbers from an input line in an list,

list = list(map(int, input().split()))

and @backbenchermmc,
Your array declaration is not correct. if have to specify array length like this,

int arr[100]; //here 100 is the length of the array.

ok boss.i try kortasi

thanks for your advise .
after a perfect array declaration it works

#include <stdio.h>

int main(){
    int max = 0,n=1,a[n];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    max = a[n-1];
    for(int i=0;i<n;i++){
        if(a[i]>max){
            max = a[i];
        }
    }
    printf("%d",max);
    return 0;
}

what’s wrong?

test_case = input();
N = input();
Ns = N.split();
set = {‘a’};
for k in Ns:
set.add(int(k));
set.remove(‘a’);
set = list(set);
print(set[len(set) - 1]);

Toph says it is correct for sample case but wrong for the hidden case. Why?

The Sample Case is a Sample Case after All.

The Sample Case is usually just given so that the solvers can get a glimpse of what the actual test cases looks like. It doesn’t usually contain most of the scenarios that you will be most likely facing within the given conditions.

Thus, even after passing the sample test case, your code might fail. You have to figure out why it failed and cope with it yourself.

n = int(input())
l = list()
for i in range(n):
    i = int(input())
	l.append(i)
l.sort()
print(l[-1])

what is the problem in this code?

#include<stdio.h>
int main()
{
    int i,n,a[100],maxx=0;

    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        if(a[i]>maxx) maxx=a[i];
    }

    printf(" %d",maxx);
}

whats the problem?

my code is showing run time error. I’ve also tried with the ‘while loop’ but it doesn’t change.
how can I avoid run time error?

The maximum value of N can be 99 but your array size is 20. You should change that to 100 and also the value of max should be 0.

1 Like

thank you mahfuz vai for pointing out the silly mistakes.
i should have read the question properly :frowning:

import java.util.Scanner;
public class solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int max = N;
		
		if(N>0 && N<100){
		for(int i=1;i<=N;++i ){
			int a = sc.nextInt();
			if(a>1 && a<1000){
				 if(a>max) max = a;
				else  ;
			}
		}System.out.println(max);
		
	}
}
}

what’s wrong?

use &n instead of &n…

///Maximum number///
// BIJON SAHA, SWE, SUST

#include<stdio.h>
int main()
{
int n,i;
scanf(“%d”, &n);
int ara[102];
int max = ara[0];

for(i=0; i<n; i++)
{
    scanf("%d", &ara[i]);
}

for(i=1; i<n ; i++)
{
    if(max < ara[i])
    max = ara[i];
}
printf("%d\n",max);


return 0;

}

/// what is the problem?///

try Int max =0;instead of max=N;