47.6k views
1 vote
Write a function which will ask users to enter numbers and return the largest number.

User Annibigi
by
4.4k points

1 Answer

4 votes

Answer:

#include<stdio.h>

int GetLargest()

{

int a[100],n,largest;

printf("Enter number of elements\\");

scanf("%d",&n);

printf("Enter elements\\");

for(int i=0;i<n;i++)

scanf("%d",&a[i]);

i=0;

largest=a[i];

while(i<n)

{

i++

if(a[i]>largest)

largets=a[i];

}

return largest;

}

void main(){

int largest;

largest=GetLargest();

printf("Largest Number is %d",largest);

}

Step-by-step explanation:

Here we define one function "GetLargest". This function reads n number of elements and finds the largest number among the n elements. Here we took one array and assumed first element is the largest element. if any element of the array is greater that that element we make that as larger and continues.at the end we are getting largest element in the n numbers and returning that to the main.

User Frederik
by
4.9k points