Maximum

#include <iostream>
using namespace std;

 int main()
 {
 	int N;
 	cin >> N;
 	cout << endl;
 	if(N>99) return 0;
 	int arr[N];
 	
 	int max = 0;
 	for(int i=0; i<N; i++)
 	{
 		cin >> arr[i];
 		if(arr[i]>max)
 			max = arr[i];
 	}
 	cout << max;
 	return 0;
 }

What is the problem in this code?

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b,c;
cin>>n;
while(cin>>a>>b>>c)
{

cout<<max(a,max(b,c))<<endl;
break;

}
return 0;
}
what’s the problem with the above code???

When I do Build and Run, my IDE shows the correct answer, but when I test it here, it shows me Wrong Answer! I can’t just find whats wrong in this code…

#include <stdio.h> 
  
int main() 
{ 
    int A, B, C; 
  
    printf("Enter the numbers A, B and C: "); 
    scanf("%d %d %d", &A, &B, &C); 
  
    if (A >= B && A >= C) 
        printf("%d is the largest number.", A); 
  
    if (B >= A && B >= C) 
        printf("%d is the largest number.", B); 
  
    if (C >= A && C >= B) 
        printf("%d is the largest number.", C); 
  
    return 0; 
}

@iker_13 Your code assumes that there will only be 3 numbers (A, B, C). But in the problem statement, it says there will be “N numbers” (where N can be anything between 1 and 100).

What is wrong with this code? Shows and runs perfectly in my IDE, but shows compilation error in toph.co.

#include <stdio.h>
int main()
{
  int i,num,n,large=0;

  printf("How many numbers: ");
  scanf("%d",&n);

  for(i=0; i<n; i++)
  {
    printf("\nEnter number %d: ",i+1);
    scanf("%d",&num);
    if(num>large)
    large=num;
  }

  printf("\n\nThe Largest Number is %d",large);

  getch();
  return 0;
}

Don’t write stuff like “How many numbers:” and “\nEnter number %d”. Online Judges (OJ) do not work this way.
Online Judges compile your code and then produce an output file against the input files which are known as test cases.
Then, If the output file produced by your code does match the Accepted output files stored in the OJ, your submission will be accepted.
Suppose you are told to read 2 integers and print their sum in a single line. The for input:

101 202

the desired output should be.

303

So, if the output of your code is

303

then the submission will be accepted.

But if the output of your code is:

The sum is 303

then your output does not match with the desired output and so the code will not be accepted.

So, in order to get your codes accepted, you have to output the result in the way which was explained in the problem statement.

Fix your code according to the problem statement to get Accepted verdict.

Whats wrong with this code? And what should I do?

#include<stdio.h>
int main()
{
    int i,n, lar, elem;
    printf("Enter total number of elements\n");
    scanf("%d",&elem);
    printf("Enter first number\n");
    scanf("%d",&n);
    lar=n;
    for(i=1; i<=elem -1;i++);
    {
        printf("n\ Enter the number \n");
        scanf("%d",&n);
        if(n>lar)
        lar=n;
    }
    printf("n\ The largest number is %d",lar);
    return 0;
}

You have already been answered @iker_13 .
Read this.

What are the things should I keep in mind to solve this problem?
This is by far the hardest one I have faced.
Suggestions please…

Is this code even right/correct?

#include<stdio.h>
int main()

{
    int n,i, lar;
    scanf("%d%d",&n,&i);
    for(i<1;i=1;i++);
    if(n>lar)
        n=lar;
    {
        printf("%d",lar);
    }

    return 0;
}

Toph shows CPU limit exceeded

@iker_13 Here are some pointers based on your previous code that you shared here:

  1. Do not print anything other than the answer. No “Enter total number of elements\n”, no extra texts.

  2. First take an input n. Then a loop should run n times and read n numbers. And every time you get the number, compare it with the largest one and see if the new number that you read is the largest one.

  3. Print just the largest number at the end as printf("%d\n", largest);. Do not print anything else.

You should only read the value of n here.

Next, fix the the loop: it should start with i = 0 and run while i < n.

Inside the loop, scanf a number and compare it with your current largest. This will then run n times inside the loop.

#include<stdio.h>
int main()
{
    int i,num[99],n;
    scanf("%d",&n);

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




}

whats wrong in here?

Looks like you figured it out already.

It’s amazing how much an extra semicolon can mess up. :slight_smile:

numbers=list(map(int,input().split()))
print(max(numbers))

what was the problem??it return output on my editor correctly but when i submit the code they say wrong answer

@tania.238473 The statement says:

The first line of the input will contain N

Here N is the number of integers that you will have read from the next line and see which one is the maximum among them.

Your code is reading just N (from the first line), and not the actual N numbers (from the second line) that you need to compare.

#include<stdio.h>
int main()
{
int a,b,c,d;
scanf(“%d\n”,d);
scanf(“%d %d %d”,&a,&b,&c);
if(a>b && a>c ){
printf(“%d”,a);
}
else if(b>a && b>c){
printf(“%d”,b);
}
else if(c>b && c>a){
printf(“%d”,c);
}
}

what is my problem

#include <stdio.h>

int main()
{
unsigned int G,N,max=1,final;
int b;
scanf(“%d”,&N);
for(b=1;b<=N;b++)
{
scanf(“%d”,&G);
if(max>G)
final=max;
else
final=G;
}
printf(“%d”,final);
return 0;
}

works just fine…but it’s still showing error…a little help please??

@SonicTitan03
What will happen if A == B == C ?
Your code will not show any output.
Try how can you fix this.

And there can be more or less than 3 numbers in the input.

you are using unsigned int but printing int.
This might be the reason.