Algorithm
Highest and Position
Adapted by Neilor Tonin, URI Brazil
Read 100 integer numbers. Print the highest read value and the input position.
Input
The input file contains 100 distinct positive integer numbers.
Output
Print the highest number read and the input position of this value, according to the given example.
Input Sample | Output Sample |
2 |
34565 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
int n, max = -1, p, i;
for (i = 1; i < 101; ++i)
{
scanf("%d", &n);
if(max < n)
max = n, p = i;
}
printf("%dn%dn", max, p>;
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <stdio.h>
int main(int argc, char const *argv[])
{
int n, max = -1, p;
for (int i = 1; i < 101; ++i)
{
scanf("%d", &n);
if(max < n)
max = n, p = i;
}
printf("%dn%dn", max, p>;
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int N =100, X, highest = 0,position = 0;
Scanner input =new Scanner(System.in);
for (int i = 1; i < = N; i++)
{
X =input.nextInt();
if (highest > X)
{
highest = highest;
position = position;
}
else
{
highest = X;
position = i;
}
}
System.out.print(highest+"n"+position+"n");
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
j=0
loc=0
for i in range(100):
n=int(input())
if(n>j):
j=n
loc=i
print(j)
print(loc+1)
Copy The Code &
Try With Live Editor
Input
Output