C Program to determine largest among n numbers

Posted: January 19, 2012 in Lab 2
#include<stdio.h>
#include<stdlib.h>
void largest(int*,int);
void largest(int *arr,int n)
{
int i,temp=*(arr+0);
for(i=0;i<(n-1);i++)
{
if(temp<*(arr+i+1))
temp=*(arr+i+1);
}
printf("%d",temp);
}
void main()
{
int *arr,i,n;
printf("Enter the no. of elements\n");
scanf("%d",&n);
arr=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%d",(arr+i));
largest(arr,n);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s