220k views
0 votes
Write a function named lastGreater that takes three arguments and returns in integer. The first argument is an integer array. The second argument is the length of the array. The third argument is an integer comparison value. Return the index of the lastelement in the array that is greater than the comparison value . If there is no element in the array greater than the comparisonvalue , then return -1.

User Friso
by
4.5k points

1 Answer

5 votes

Answer:

See explaination for the code

Step-by-step explanation:

#include<stdio.h>

#include<conio.h>

int lastGreater(int a[], int len, int co)

{

int i,lar=-1;

for(i=0;i<len;i++)

{

if(a[i]>co)

{

lar=a[i];

}

}

return lar;

}

void main()

{

int a[]={1,7,5,9,4};

int c=5,n=5,lar;

lar=lastGreater(a,n,c);

printf("Last Large number in array is %d",lar);

getch();

}

User Mariz Melo
by
5.9k points