Skip to content
doubtly

Write a program to find the largest of n numbers taken from user, using a function the array of numbers must

Write a program to find the largest of n numbers taken from user, using a function the array of numbers must be passed to the function. The largest number must be found in the function and returned to the main function.
Doubtly Asked Student doubt Save WhatsApp Report

1 answer

Best answer

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[100],large;
int largest (int a[], int n);
clrscr();
printf("Enter the number of elements:");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
{
printf("Enter a value:");
scanf("%d",&a[i]);
}
large=largest(a,n);
printf("The largest number is %d",large);
getch();
}
int largest (int a[], int n)
{
int i,large;
large=a[0];
for(i=1;i<=n-1;i++)
{
if(large<a[i])
large=a[i];
}
return large;
}
Doubtly · 11 Jun 2022 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.