Find the largest element/value form a given array using function
#include<stdio.h>
#define MAX 100
int getMaxvalue();
int size;
int main()
{
int a[MAX],max,i;
printf("Enter the size of the array: \n");
scanf("%d",&size);
printf("Enter %d elements of an array: \n", size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
max=getMaxvalue(a);
printf("Largest element of an array is: %d",max);
return 0;
}
int getMaxvalue(int a[])
{
int i=1,max;
max=a[0];
while(i < size)
{
if(max<a[i])
max=a[i];
i++;
}
return max;
}
#include<stdio.h>
#define MAX 100
int getMaxvalue();
int size;
int main()
{
int a[MAX],max,i;
printf("Enter the size of the array: \n");
scanf("%d",&size);
printf("Enter %d elements of an array: \n", size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
max=getMaxvalue(a);
printf("Largest element of an array is: %d",max);
return 0;
}
int getMaxvalue(int a[])
{
int i=1,max;
max=a[0];
while(i < size)
{
if(max<a[i])
max=a[i];
i++;
}
return max;
}
No comments:
Post a Comment