Given N numbers, find the one that is of the highest value and print it.
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
Thank you very much brother, It will be a pleasure to me if I can contact (incase I have stacked in any problem ) with you through email / fb.
Please give me your id.
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.