program that reads integers from the standard input (until it gets a negative number) and put them into an array. After that it finds the highest number in the array that is less than 100 and prints that to the standard output. It should return 0 if the array has no numbers less than 100.
Answers
Note: I am using C++ Language.
codes:
#include<iostream>
using namespace std;
//Function to find biggest number
int big(int arr[] ) {
int i=0 ,biggest ;
while (arr[i]>=0 ){
biggest = arr[i] ;
if( biggest < arr[i+1]){
biggest = arr[i+1] ;
}
i++ ;
}
return biggest ;
}
int main ( ){
int num,i=0 ,arr[20], flag = 0;
//Codes to take numbers as input
while(num>=0){
cout<<"Enter numbers: ";
cin>>num;
arr[i] = num ;
i++;
}
//Codes to check number is less than 100 as well as biggest number.
i=0;
while(arr[i]>=0) {
if(arr[i]<100 && arr[i]==big(arr)){
flag = 1 ;
break;
}
i++ ;
}
if(flag==1) {
cout<<"\nThe highest number is " <<arr[i] ;
}
else cout<<"\nThe result is : 0" ;
//Codes to see the array elements for cross verification
i=0;
cout<<"\n\nArray contains: " ;
while(arr[i]>=0) {
cout<<arr[i] <<" " ;
i++ ;
}
return 0;
}
** Please mark this ans as Brainliest answer. Thank you!
Answer:
/* solution is a C program that reads integers from the standard input (until it gets a negative number) and put them into an array. After that it finds the highest number in the array that is less than 100 and prints that to the standard output. It should return 0 if the array has no numbers less than 100. */
#include <stdio.h>
int main ( )
{
int i,j,num, arr[100],Max,flag;
for(i=0;num>=0;i++)
{
printf("Enter any number less than 100");
scanf("%d",&num);
if (num>=0)
{
arr[i] = num ;
}
else {
break;
}
}
//Codes to check biggest number.
j=0;
Max = arr[j];
while(j <= i ) {
if(Max <= arr[j+1])
{
Max= arr[j+1];
}
j++;
}
printf("\nThe highest number is %d" ,Max) ;
return 0;
}